squlearn.encoding_circuit
.ChebyshevTower
- class squlearn.encoding_circuit.ChebyshevTower(num_qubits: int, num_features: int, num_chebyshev: int, alpha: float = 1.0, num_layers: int = 1, rotation_gate: str = 'ry', hadamard_start: bool = True, arrangement: str = 'block', nonlinearity: str = 'arccos')
A feature-map that is based on the Chebyshev Tower encoding.
Example for 4 qubits, a 2 dimensional feature vector, 2 Chebyshev terms per feature, and 2 layers:
(
Source code
,png
,hires.png
,pdf
)The encoding gate and the scaling factor can be adjusted by parameters. It is also possible to change the indexing of the features.
- Parameters:
num_qubits (int) – Number of qubits of the ChebyshevTower encoding circuit
num_features (int) – Dimension of the feature vector
n_chebyshev (int) – Number of Chebyshev tower terms per feature dimension
alpha (float) – Scaling factor of Chebyshev tower
num_layers (int) – Number of layers
rotation_gate (str) – Rotation gate to use. Either
rx
,ry
orrz
(default:ry
)hadamard_start (bool) – If true, the circuit starts with a layer of Hadamard gates (default: True)
arrangement (str) – Arrangement of the layers, either
block
oralternating
.block
: The features are stacked together,alternating
: The features are placed alternately (default:block
).nonlinearity (str) – Mapping function to use for the feature encoding. Either
arccos
orarctan
(default:arccos
)
- 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 = None) QuantumCircuit
Generates and returns the circuit of the Chebyshev 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 Chebyshev Tower encoding
- 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(**kwargs) ChebyshevTower
Sets value of the encoding circuit hyper-parameters.
- Parameters:
params – Hyper-parameters and their values, e.g.
num_qubits=2
.