# 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 with log2(feature_dimension) qubits. As long as there are free parameters, this circuit holds a placeholder instruction and can not be decomposed. Once all parameters are bound, the placeholder is replaced by a state initialization and can be unrolled.

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

Examples:

from qiskit.ml.circuit.library import RawFeatureVector
circuit = RawFeatureVector(4)
print(circuit.num_qubits)
# prints: 2

print(circuit.draw(output='text'))
# prints:
#      ┌──────┐
# q_0: ┤0     ├
#      │  Raw │
# 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                                 ├
#      │  initialize(0.70711,0,0,0.70711) │
# q_1: ┤1                                 ├
#      └──────────────────────────────────┘

Parameters

feature_dimension (Optional[int]) -- The feature dimension and number of qubits.

Methods

 add_bits Add Bits to the circuit. add_calibration Register a low-level, custom pulse definition for the given gate. add_register Add registers. append Append one or more instructions to the end of the circuit, modifying the circuit in place. assign_parameters Call the initialize instruction. barrier Apply Barrier. bind_parameters Bind parameters. cast Best effort to cast value to type. cbit_argument_conversion Converts several classical bit representations (such as indexes, range, etc.) into a list of classical bits. ccx Apply CCXGate. ch Apply CHGate. cls_instances Return the current number of instances of this class, useful for auto naming. cls_prefix Return the prefix to use for auto naming. cnot Apply CXGate. combine DEPRECATED - Returns rhs appended to self if self contains compatible registers. compose Compose circuit with other circuit or instruction, optionally permuting wires. control Control this circuit on num_ctrl_qubits qubits. copy Copy the circuit. count_ops Count each operation kind in the circuit. cp Apply CPhaseGate. crx Apply CRXGate. cry Apply CRYGate. crz Apply CRZGate. cswap Apply CSwapGate. csx Apply CSXGate. cu Apply CUGate. cu1 Apply CU1Gate. cu3 Apply CU3Gate. cx Apply CXGate. cy Apply CYGate. cz Apply CZGate. dcx Apply DCXGate. decompose Call a decomposition pass on this circuit, to decompose one level (shallow decompose). delay Apply Delay. depth Return circuit depth (i.e., length of critical path). diagonal Attach a diagonal gate to a circuit. draw Draw the quantum circuit. ecr Apply ECRGate. extend DEPRECATED - Append QuantumCircuit to the RHS if it contains compatible registers. fredkin Apply CSwapGate. from_qasm_file Take in a QASM file and generate a QuantumCircuit object. from_qasm_str Take in a QASM string and generate a QuantumCircuit object. get_instructions Get instructions matching name. h Apply HGate. hamiltonian Apply hamiltonian evolution to qubits. has_register Test if this circuit has the register r. i Apply IGate. id Apply IGate. initialize Initialize qubits in a specific state. inverse Invert (take adjoint of) this circuit. iso Attach an arbitrary isometry from m to n qubits to a circuit. isometry Attach an arbitrary isometry from m to n qubits to a circuit. iswap Apply iSwapGate. mcp Apply MCPhaseGate. mcrx Apply Multiple-Controlled X rotation gate mcry Apply Multiple-Controlled Y rotation gate mcrz Apply Multiple-Controlled Z rotation gate mct Apply MCXGate. mcu1 Apply MCU1Gate. mcx Apply MCXGate. measure Measure quantum bit into classical bit (tuples). measure_active Adds measurement to all non-idle qubits. measure_all Adds measurement to all qubits. ms Apply MSGate. num_connected_components How many non-entangled subcircuits can the circuit be factored to. num_nonlocal_gates Return number of non-local gates (i.e. num_tensor_factors Computes the number of tensor factors in the unitary (quantum) part of the circuit only. num_unitary_factors Computes the number of tensor factors in the unitary (quantum) part of the circuit only. p Apply PhaseGate. pauli Apply PauliGate. power Raise this circuit to the power of power. qasm Return OpenQASM string. qbit_argument_conversion Converts several qubit representations (such as indexes, range, etc.) into a list of qubits. qubit_duration Return the duration between the start and stop time of the first and last instructions, excluding delays, over the supplied qubits. qubit_start_time Return the start time of the first instruction, excluding delays, over the supplied qubits. qubit_stop_time Return the stop time of the last instruction, excluding delays, over the supplied qubits. r Apply RGate. rcccx Apply RC3XGate. rccx Apply RCCXGate. remove_final_measurements Removes final measurement on all qubits if they are present. repeat Repeat this circuit reps times. reset Reset q. reverse_bits Return a circuit with the opposite order of wires. reverse_ops Reverse the circuit by reversing the order of instructions. rv Apply RVGate. rx Apply RXGate. rxx Apply RXXGate. ry Apply RYGate. ryy Apply RYYGate. rz Apply RZGate. rzx Apply RZXGate. rzz Apply RZZGate. s Apply SGate. save_amplitudes Save complex statevector amplitudes. save_amplitudes_squared Save squared statevector amplitudes (probabilities). save_density_matrix Save the current simulator quantum state as a density matrix. save_expectation_value Save the expectation value of a Hermitian operator. save_expectation_value_variance Save the expectation value of a Hermitian operator. save_matrix_product_state Save the current simulator quantum state as a matrix product state. save_probabilities Save measurement outcome probabilities vector. save_probabilities_dict Save measurement outcome probabilities vector. save_stabilizer Save the current stabilizer simulator quantum state as a Clifford. save_state Save the current simulator quantum state. save_statevector Save the current simulator quantum state as a statevector. save_statevector_dict Save the current simulator quantum state as a statevector as a dict. save_superop Save the current state of the superop simulator. save_unitary Save the current state of the unitary simulator. sdg Apply SdgGate. set_density_matrix Set the density matrix state of the simulator. set_matrix_product_state Set the matrix product state of the simulator. set_stabilizer Set the Clifford stabilizer state of the simulator. set_statevector Set the statevector state of the simulator. set_superop Set the superop state of the simulator. set_unitary Set the state state of the simulator. size Returns total number of gate operations in circuit. snapshot Take a statevector snapshot of the internal simulator representation. snapshot_density_matrix Take a density matrix snapshot of simulator state. snapshot_expectation_value Take a snapshot of expectation value of an Operator. snapshot_probabilities Take a probability snapshot of the simulator state. snapshot_stabilizer Take a stabilizer snapshot of the simulator state. snapshot_statevector Take a statevector snapshot of the simulator state. squ Decompose an arbitrary 2*2 unitary into three rotation gates. swap Apply SwapGate. sx Apply SXGate. sxdg Apply SXdgGate. t Apply TGate. tdg Apply TdgGate. tensor Tensor self with other. to_gate Create a Gate out of this circuit. to_instruction Create an Instruction out of this circuit. toffoli Apply CCXGate. u Apply UGate. u1 Apply U1Gate. u2 Apply U2Gate. u3 Apply U3Gate. uc Attach a uniformly controlled gates (also called multiplexed gates) to a circuit. ucrx Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit. ucry Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit. ucrz Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit. unitary Apply unitary gate to q. width Return number of qubits plus clbits in circuit. x Apply XGate. y Apply YGate. z Apply ZGate.

Attributes

ancillas

Returns a list of ancilla bits in the order that the registers were added.

calibrations

Return calibration dictionary.

The custom pulse definition of a given gate is of the form

{'gate_name': {(qubits, params): schedule}}

clbits

Returns a list of classical bits in the order that the registers were added.

data
extension_lib = 'include "qelib1.inc";'
feature_dimension

Return the feature dimension.

Return type

int

Returns

The feature dimension, which is 2 ** num_qubits.

global_phase

Return the global phase of the circuit in radians.

header = 'OPENQASM 2.0;'
instances = 16
metadata

The user provided metadata associated with the circuit

The metadata for the circuit is a user provided dict of metadata for the circuit. It will not be used to influence the execution or operation of the circuit, but it is expected to be passed between all transforms of the circuit (ie transpilation) and that providers will associate any circuit metadata with the results it returns from execution of that circuit.

num_ancillas

Return the number of ancilla qubits.

num_clbits

Return number of classical bits.

num_parameters
Return type

int

num_qubits

Returns the number of qubits in this circuit.

Return type

int

Returns

The number of qubits.

ordered_parameters

Return the free parameters in the RawFeatureVector.

Return type

List[ParameterExpression]

Returns

A list of the free parameters.

parameters

Return the free parameters in the RawFeatureVector.

Return type

Set[ParameterExpression]

Returns

A set of the free parameters.

prefix = 'circuit'
qregs

A list of the quantum registers associated with the circuit.

qubits

Returns a list of quantum bits in the order that the registers were added.