RawFeatureVector¶
- class RawFeatureVector(feature_dimension)[source]¶
Bases:
qiskit.circuit.library.blueprintcircuit.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 ├ # └───────────────────────────────────────────────┘
- Tham số
feature_dimension (
Optional
[int
]) -- The feature dimension from which the number of qubits is inferred asn_qubits = log2(feature_dim)
Attributes
Return the feature dimension.
Returns the number of qubits in this circuit.
Methods