squlearn.encoding_circuit
.ChebyshevPQC
- class squlearn.encoding_circuit.ChebyshevPQC(num_qubits: int, num_features: int, num_layers: int = 1, closed: bool = True, entangling_gate: str = 'crz', alpha: float = 4.0, nonlinearity: str = 'arccos')
Chebyshev Encoding Circuit from reference [1].
The encoding circuit consists of three elements:
Basis change in the form of a trainable rotation around the y-axis at start and end.
Non-linear encoding of the features via the Chebyshev polynomials from Rx gates. The degree of the Chebyshev polynomials is optimized during training.
Parameterized two-qubit controlled or RZZ rotations
and 3. form a layer that can be repeated multiple times.
Example for 4 qubits, a 2 dimensional feature vector and 2 layers:
(
Source code
,png
,hires.png
,pdf
)The entangling gate can be chosen between
crz
andrzz
. The latter is more hardware efficient. Also, the entangling between the first and the last qubit can be switched off via theclosed
parameter to avoid swap gates.- Parameters:
num_qubits (int) – Number of qubits of the ChebyshevPQC encoding circuit
num_features (int) – Dimension of the feature vector
num_layers (int) – Number of layers of the Chebyshev encoding and the two qubit manipulation (default: 1)
closed (bool) – If false, the last and the first qubit are not entangled (default: True)
entangling_gate (str) – Entangling gate to use. Either
crz
orrzz
(default:crz
)alpha (float) – Maximum value of the Chebyshev Tower initial parameters, i.e. parameters that appear in the arccos encoding. (default: 4.0)
nonlinearity (str) – Mapping function to use for the feature encoding. Either
arccos
orarctan
(default:arccos
)
References
[1]: D. A. Kreplin and M. Roth “Reduction of finite sampling noise in quantum neural networks”. arXiv:2306.01639 (2023).
- draw(output: str = None, feature_label: str = 'x', parameter_label: str = 'p', decompose: bool = False, **kwargs) None
Draws the encoding circuit circuit using the QuantumCircuit.draw() function.
- Parameters:
feature_label (str) – Label for the feature vector (default:”x”).
parameter_label (str) – Label for the parameter vector (default:”p”).
decompose (bool) – If True, the circuit is decomposed before printing (default: False).
kwargs – Additional arguments from Qiskit’s QuantumCircuit.draw() function.
- Returns:
Returns the circuit in qiskit QuantumCircuit.draw() format
- generate_initial_parameters(seed: int | None = None) ndarray
Generates random parameters for the ChebyshevPQC encoding circuit
- Parameters:
seed (Union[int,None]) – Seed for the random number generator (default: None)
- Returns:
The randomly generated parameters
- get_cheb_indices(flatten: bool = True)
Function that returns the indices of the parameters involved in the Chebyshev encoding.
- Parameters:
flatten (bool) – If true, the indices are returned as a flat list, otherwise as a list of lists, where the outer list corresponds to the layers (default: True)
- get_circuit(features: ParameterVector | ndarray, parameters: ParameterVector | ndarray) QuantumCircuit
Returns the circuit of the ChebyshevPQC encoding circuit
- Parameters:
features (Union[ParameterVector,np.ndarray]) – Input vector of the features from which the gate inputs are obtained
param_vec (Union[ParameterVector,np.ndarray]) – Input vector of the parameters from which the gate inputs are obtained
- Returns:
Returns the circuit in Qiskit’s QuantumCircuit format
- get_params(deep: bool = True) dict
Returns hyper-parameters and their values of the ChebyshevPQC encoding circuit
- Parameters:
deep (bool) – If True, also the parameters for contained objects are returned (default=True).
- Returns:
Dictionary with hyper-parameters and values.
- set_params(**kwargs) ChebyshevPQC
Sets value of the encoding circuit hyper-parameters.
- Parameters:
params – Hyper-parameters and their values, e.g.
num_qubits=2
.