RawFeatureVector#
- class RawFeatureVector(feature_dimension)[kaynak]#
Bases:
BlueprintCircuit
The raw feature vector circuit.
This circuit acts as parameterized initialization for statevectors with
feature_dimension
dimensions, thus withlog2(feature_dimension)
qubits. The circuit contains a placeholder instruction that can only be synthesized/defined when all parameters are bound.In ML, this circuit can be used to load the training data into qubit amplitudes. It does not apply an kernel transformation (therefore, it is a “raw” feature vector).
Since initialization is implemented via a
QuantumCircuit.initialize()
call, this circuit can’t be used with gradient based optimizers, one can see a warning that gradients can’t be computed.Examples:
from qiskit_machine_learning.circuit.library import RawFeatureVector circuit = RawFeatureVector(4) print(circuit.num_qubits) # prints: 2 print(circuit.draw(output='text')) # prints: # ┌───────────────────────────────────────────────┐ # q_0: ┤0 ├ # │ PARAMETERIZEDINITIALIZE(x[0],x[1],x[2],x[3]) │ # q_1: ┤1 ├ # └───────────────────────────────────────────────┘ print(circuit.ordered_parameters) # prints: [Parameter(p[0]), Parameter(p[1]), Parameter(p[2]), Parameter(p[3])] import numpy as np state = np.array([1, 0, 0, 1]) / np.sqrt(2) bound = circuit.assign_parameters(state) print(bound.draw()) # prints: # ┌───────────────────────────────────────────────┐ # q_0: ┤0 ├ # │ PARAMETERIZEDINITIALIZE(0.70711,0,0,0.70711) │ # q_1: ┤1 ├ # └───────────────────────────────────────────────┘
- Parametreler:
feature_dimension (int | None) – The feature dimension from which the number of qubits is inferred as
n_qubits = log2(feature_dim)
Attributes
- feature_dimension#
Return the feature dimension.
- Dönüşler:
The feature dimension, which is
2 ** num_qubits
.
- num_qubits#
Returns the number of qubits in this circuit.
- Dönüşler:
The number of qubits.
Methods