squlearn.encoding_circuit
.KyriienkoEncodingCircuit
- class squlearn.encoding_circuit.KyriienkoEncodingCircuit(num_qubits: int, num_features: int = 1, encoding_style: str = 'chebyshev_tower', variational_arrangement: str = 'HEA', num_encoding_layers: int = 1, num_variational_layers: int = 1, rotation_gate: str = 'ry', block_width: int = 2, block_depth: int = 1)
Collection of encoding circuits introduced by Kyriienko et al. in reference [1].
The following circuits are implemented:
chebyshev_tower
encoding (Eq. 15),chebyshev_sparse
encoding (Eq. 14)chebyshev_product
encoding (Eq. 5).
Each encoding circuit is followed by a variational circuit as defined in reference [1], RZ-RX-RZ layers followed by entangling layers. Two arrangements are possible:
HEA
: Hardware Efficient Ansatz, with consecutive entangling layers (See Figure 5a or Section IIIB in [1])ABA
: Alternating Block Ansatz with consecutive shifted entangling layers in each block (See Figure 5b or Section IIIB in [1])
Example: 4 qubits, a 2 dimensional feature vector, 1 encoding layer, 2 variational layers, variational arrangement ABA and Chebyshev tower encoding:
(
Source code
,png
,hires.png
,pdf
)- Parameters:
num_qubits (int) – Number of qubits of the encoding circuit
encoding_style (str) – Style of the encoding. Options are
'chebyshev_tower'
(default),'chebyshev_sparse'
and'chebyshev_product'
(see reference [1], Equation 15, 14 and 5 respectively)variational_arrangement (str) – Arrangement of the variational layers. Options are
'HEA'
(default) and'ABA'
(see reference [1], section IIIB)num_encoding_layers (int) – Number of encoding layers (default: 1)
num_variational_layers (int) – Number of variational layers (default: 1)
rotation_gate (str) – Rotation gate to use. Either
'rx'
,'ry'
or'rz'
(default:'ry'
as in reference [1])num_features (int) – Dimension of the feature vector (default: 1)
block_width (int) – Only necessary for arrangement
'ABA'
. Width (vertical) of each blocks for the ABA arrangement (default: 2), also refered as Nb in the paper. Must be a divisor of the number of qubitsblock_depth (int) – Only necessary for arrangement
'ABA'
. Depth (horizontal) of each blocks for the ABA arrangement (default: 1), also refered as b in the paper.
References
[1]: O. Kyriienko et al., “Solving nonlinear differential equations with differentiable quantum circuits”, arXiv:2011.10395 (2021).
- compose(x, concatenate_features=True, concatenate_parameters=False)
Composition of encoding circuits with options for handling features and parameters
Number of qubits and features have to be equal in both encoding circuits! The special function and properties of the both encoding circuits are lost by this composition.
- Parameters:
self (EncodingCircuitBase) – right / first encoding circuit
x (EncodingCircuitBase) – left / second encoding circuit
- Returns:
Returns the composed encoding circuit as special class ComposedEncodingCircuit
- 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 encoding circuit
- Parameters:
seed (Union[int,None]) – Seed for the random number generator (default: None)
- Returns:
The randomly generated parameters
- get_circuit(features: ParameterVector | ndarray, parameters: ParameterVector | ndarray) QuantumCircuit
Generates and returns the circuit of the Kyriienko encoding circuit
- Parameters:
features (Union[ParameterVector, np.ndarray]) – The features to encode
parameters (Union[ParameterVector, np.ndarray]) – The parameters of the encoding circuit
- Returns:
The encoding circuit
- Return type:
QuantumCircuit
- get_params(deep: bool = True) dict
Returns hyper-parameters and their values of the Kyriienko encoding circuit
- Parameters:
deep (bool) – If True, also the parameters for contained objects are returned (default=True).
- Returns:
Dictionary with hyper-parameters and values.
- inverse()
Returns the inverse of the encoding circuit.
- Returns:
The inverse of the encoding circuit
- set_params(**params) EncodingCircuitBase
Sets value of the encoding circuit hyper-parameters.
- Parameters:
params – Hyper-parameters and their values, e.g.
num_qubits=2
.