squlearn.encoding_circuit
.HighDimEncodingCircuit
- class squlearn.encoding_circuit.HighDimEncodingCircuit(num_qubits: int, num_features: int, cycling: bool = True, cycling_type: str = 'saw', num_layers: None | int = None, layer_type: str = 'rows', entangling_gate: str = 'iswap')
The high-dimensional encoding circuit from reference [1].
A encoding circuit that can be used for the classification of high-dimensional data.
Example for 5 qubits, a 23 dimensional feature vector and 2 layers:
(
Source code
,png
,hires.png
,pdf
)The indexing of the feature vector can be changed by the arguments
cycling
,cycling_type
andlayer_type
.- Parameters:
num_qubits (int) – Number of qubits of the HighDim encoding circuit
num_features (int) – Dimension of the feature vector
cycling (bool) – If true, the assignment of gates cycles, i.e. if reaching the last feature, the layer is filled by starting again from the first feature. If false, the gates are left out after reaching the last feature. (default: true)
cycling_type (str) – Defines, how the indices are cycled.n
saw
: restarts by 0, e.g. 0,1,2,3,0,1,2,3 (recommended);hat
: goes up and then down, e.g. 0,1,2,3,2,1,0,1,2,3number_of_layers (int) – Sets the number of layer repetitions. If not given, the number of layers is determined automatically by the number of features and qubits. If the given number of layers is to low, a error is thrown.
layer_type (str) – Defines in which directions the features are assigned to the gates.
columns
: iteration in columns (as shown in the example above);rows
: iteration in rows.entangling_gate (str) – Entangling gates that are used in the entangling layer. Either
iswap
orcx
(default:iswap
)
References
[1]: Peters, Evan, et al. “Machine learning of high dimensional data on a noisy quantum processor.” npj Quantum Information 7.1 (2021): 161.
- 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
Returns the circuit of the HighDim 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:
The circuit of the high-dimensional encoding circuit
- get_params(deep: bool = True) dict
Returns hyper-parameters and their values of the HighDim 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(**params) EncodingCircuitBase
Sets value of the encoding circuit hyper-parameters.
- Parameters:
params – Hyper-parameters and their values, e.g.
num_qubits=2
.