squlearn.encoding_circuit.MultiControlEncodingCircuit

class squlearn.encoding_circuit.MultiControlEncodingCircuit(num_qubits: int, num_layers: int = 1, num_features: int = None, closed: bool = True, final_encoding=False)

Encoding circuit with HZ encoding followed by controlled Rx, Ry Rz rotations.

Example for 4 qubits, a 2 dimensional feature vector and 1 layer:

(Source code, png, hires.png, pdf)

../../_images/squlearn-encoding_circuit-MultiControlEncodingCircuit-1.png

The circuit is repeated for the number of layers. The circuit is closed by default, i.e. the last qubit is entangled with the first one. The encoding can be optionally repeated at the end to make the previous rotations not redundant in a fidelity kernel setting.

Parameters:
  • num_qubits (int) – Number of qubits of the MultiControlEncodingCircuit encoding circuit

  • num_layers (int) – Number of layers (default: 1)

  • num_features (int) – Dimension of the feature vector (default: None)

  • closed (bool) – If true, the last and the first qubit are entangled; not necessarily hardware efficient! (default: true)

  • final_encoding (bool) – If True, the encoding is repeated at the end (default: False)

compose(x, concatenate_features=False, concatenate_parameters=False, num_circuit_features: Tuple[int, int] = (None, None))

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

  • concatenate_features (bool) – If True, the features of both encoding circuits are concatenated (default: False). If False, the features of both encoding circuits are taken

  • concatenate_parameters (bool) – If True, the parameters of both encoding circuits are concatenated (default: False). If False, the parameters of both encoding circuits are taken

  • num_circuit_features (Tuple[int, int]) – Tuple of the number of features for both encoding circuits. This has to be provided if concatenate_features is True otherwise an error is raised.

Returns:

Returns the composed encoding circuit as special class ComposedEncodingCircuit

draw(output: str = None, num_features: int = None, feature_label: str = 'x', parameter_label: str = 'p', decompose: bool = False, **kwargs) None

Draws the encoding circuit using the QuantumCircuit.draw() function.

Parameters:
  • output (str) – Output format of the drawing (default: None).

  • num_features (int) – Number of features to draw the circuit with (default: None).

  • 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.

Raises:

ValueError – Raised if the number of features is not provided.

Returns:

Returns the circuit in qiskit QuantumCircuit.draw() format

generate_initial_parameters(num_features: int, seed: int | None = None) ndarray

Generates random parameters for the encoding circuit

Parameters:
  • num_features (int) – Number of features of the input data

  • 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

Returns the circuit of the MultiControlEncodingCircuit 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_feature_bounds(num_features: int) ndarray

Returns the feature bounds expanded for a given number of features.

Parameters:

num_features (int) – Number of features to expand the bounds for.

Returns:

Feature bounds expanded for the number of features.

Return type:

np.ndarray

get_params(deep: bool = True) dict

Returns hyper-parameters and their values of the MultiControlEncodingCircuit 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.