RawFeatureVector

class RawFeatureVector(feature_dimension)[source]

Bases: BlueprintCircuit

The raw feature vector circuit.

This circuit acts as parameterized initialization for statevectors with feature_dimension dimensions, thus with log2(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                                              ├
#      └───────────────────────────────────────────────┘
Parameters:

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.

Returns:

The feature dimension, which is 2 ** num_qubits.

num_qubits

Returns the number of qubits in this circuit.

Returns:

The number of qubits.

name: str

A human-readable name for the circuit.

cregs: list[ClassicalRegister]

A list of the ClassicalRegisters in this circuit. You should not mutate this.

duration: int | float | None

The total duration of the circuit, set by a scheduling transpiler pass. Its unit is specified by unit.

unit

The unit that duration is specified in.

Methods