PauliFeatureMap

class PauliFeatureMap(feature_dimension=None, reps=2, entanglement='full', paulis=None, data_map_func=None, parameter_prefix='x', insert_barriers=False)[source]

The Pauli Expansion circuit.

The Pauli Expansion circuit is a data encoding circuit that transforms input data \(\vec{x} \in \mathbb{R}^n\) as

\[U_{\Phi(\vec{x})}=\exp\left(i\sum_{S\subseteq [n]} \phi_S(\vec{x})\prod_{i\in S} P_i\right)\]

The circuit contains reps repetitions of this transformation. The variable \(P_i \in \{ I, X, Y, Z \}\) denotes the Pauli matrices. The index \(S\) describes connectivities between different qubits or datapoints: \(S \in \{\binom{n}{k}\ combinations,\ k = 1,... n \}\). Per default the data-mapping \(\phi_S\) is

\[\begin{split}\phi_S(\vec{x}) = \begin{cases} x_0 \text{ if } k = 1 \\ \prod_{j \in S} (\pi - x_j)\end{split}\]

For example, if the Pauli strings are chosen to be \(P_0 = Z\) and \(P_{0,1} = YY\) on 2 qubits and with 1 repetition using the default data-mapping, the Pauli evolution feature map is represented by:

┌───┐┌──────────────┐┌──────────┐                                             ┌───────────┐
┤ H ├┤ U1(2.0*x[0]) ├┤ RX(pi/2) ├──■───────────────────────────────────────■──┤ RX(-pi/2) ├
├───┤├──────────────┤├──────────┤┌─┴─┐┌─────────────────────────────────┐┌─┴─┐├───────────┤
┤ H ├┤ U1(2.0*x[1]) ├┤ RX(pi/2) ├┤ X ├┤ U1(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├┤ RX(-pi/2) ├
└───┘└──────────────┘└──────────┘└───┘└─────────────────────────────────┘└───┘└───────────┘

Please refer to ZFeatureMap for the case \(k = 1\), \(P_0 = Z\) and to ZZFeatureMap for the case \(k = 2\), \(P_0 = Z\) and \(P_{0,1} = ZZ\).

Examples

>>> prep = PauliFeatureMap(2, reps=1, paulis=['ZZ'])
>>> print(prep)
     ┌───┐
q_0: ┤ H ├──■───────────────────────────────────────■──
     ├───┤┌─┴─┐┌─────────────────────────────────┐┌─┴─┐
q_1: ┤ H ├┤ X ├┤ U1(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├
     └───┘└───┘└─────────────────────────────────┘└───┘
>>> prep = PauliFeatureMap(2, reps=1, paulis=['Z', 'XX'])
>>> print(prep)
     ┌───┐┌──────────────┐┌───┐                                             ┌───┐
q_0: ┤ H ├┤ U1(2.0*x[0]) ├┤ H ├──■───────────────────────────────────────■──┤ H ├
     ├───┤├──────────────┤├───┤┌─┴─┐┌─────────────────────────────────┐┌─┴─┐├───┤
q_1: ┤ H ├┤ U1(2.0*x[1]) ├┤ H ├┤ X ├┤ U1(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├┤ H ├
     └───┘└──────────────┘└───┘└───┘└─────────────────────────────────┘└───┘└───┘
>>> prep = PauliFeatureMap(2, reps=1, paulis=['ZY'])
>>> print(prep)
     ┌───┐┌──────────┐                                             ┌───────────┐
q_0: ┤ H ├┤ RX(pi/2) ├──■───────────────────────────────────────■──┤ RX(-pi/2) ├
     ├───┤└──────────┘┌─┴─┐┌─────────────────────────────────┐┌─┴─┐└───────────┘
q_1: ┤ H ├────────────┤ X ├┤ U1(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├─────────────
     └───┘            └───┘└─────────────────────────────────┘└───┘
>>> from qiskit.circuit.library import EfficientSU2
>>> prep = PauliFeatureMap(3, reps=3, paulis=['Z', 'YY', 'ZXZ'])
>>> wavefunction = EfficientSU2(3)
>>> classifier = prep.compose(wavefunction
>>> classifier.num_parameters
27
>>> classifier.count_ops()
OrderedDict([('cx', 39), ('rx', 36), ('u1', 21), ('h', 15), ('ry', 12), ('rz', 12)])

References

[1]: Havlicek et al. (2018), Supervised learning with quantum enhanced feature spaces.

arXiv:1804.11326

Create a new Pauli expansion circuit.

Parameters
  • feature_dimension (Optional[int]) – Number of qubits in the circuit.

  • reps (int) – The number of repeated circuits.

  • entanglement (Union[str, List[List[int]], Callable[[int], List[int]]]) – Specifies the entanglement structure. Refer to NLocal for detail.

  • paulis (Optional[List[str]]) – A list of strings for to-be-used paulis. If None are provided, ['Z', 'ZZ'] will be used.

  • data_map_func (Optional[Callable[[ndarray], float]]) – A mapping function for data x which can be supplied to override the default mapping from self_product().

  • parameter_prefix (str) – The prefix used if default parameters are generated.

  • insert_barriers (bool) – If True, barriers are inserted in between the evolution instructions and hadamard layers.

Attributes

PauliFeatureMap.clbits

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

PauliFeatureMap.data

Return the circuit data (instructions and context).

PauliFeatureMap.entanglement

Get the entanglement strategy.

PauliFeatureMap.entanglement_blocks

The blocks in the entanglement layers.

PauliFeatureMap.extension_lib

PauliFeatureMap.feature_dimension

Returns the feature dimension (which is equal to the number of qubits).

PauliFeatureMap.header

PauliFeatureMap.initial_state

Return the initial state that is added in front of the n-local circuit.

PauliFeatureMap.insert_barriers

If barriers are inserted in between the layers or not.

PauliFeatureMap.instances

PauliFeatureMap.n_qubits

Deprecated, use num_qubits instead.

PauliFeatureMap.num_clbits

Return number of classical bits.

PauliFeatureMap.num_layers

Return the number of layers in the n-local circuit.

PauliFeatureMap.num_parameters

Convenience function to get the number of parameter objects in the circuit.

PauliFeatureMap.num_parameters_settable

The number of distinct parameters.

PauliFeatureMap.num_qubits

Returns the number of qubits in this circuit.

PauliFeatureMap.ordered_parameters

The parameters used in the underlying circuit.

PauliFeatureMap.parameter_bounds

The parameter bounds for the unbound parameters in the circuit.

PauliFeatureMap.parameters

Get the Parameter objects in the circuit.

PauliFeatureMap.paulis

The Pauli strings used in the entanglement of the qubits.

PauliFeatureMap.preferred_init_points

The initial points for the parameters.

PauliFeatureMap.prefix

PauliFeatureMap.qregs

A list of the quantum registers associated with the circuit.

PauliFeatureMap.qubits

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

PauliFeatureMap.reps

The number of times rotation and entanglement block are repeated.

PauliFeatureMap.rotation_blocks

The blocks in the rotation layers.

Methods

PauliFeatureMap.AND(qr_variables, qb_target, …)

Build a collective conjunction (AND) circuit in place using mct.

PauliFeatureMap.OR(qr_variables, qb_target, …)

Build a collective disjunction (OR) circuit in place using mct.

PauliFeatureMap.__getitem__(item)

Return indexed operation.

PauliFeatureMap.__len__()

Return number of operations in circuit.

PauliFeatureMap.add_layer(other[, …])

Append another layer to the NLocal.

PauliFeatureMap.add_register(*regs)

Add registers.

PauliFeatureMap.append(instruction[, qargs, …])

Append one or more instructions to the end of the circuit, modifying the circuit in place.

PauliFeatureMap.assign_parameters(param_dict)

Assign parameters to the n-local circuit.

PauliFeatureMap.barrier(*qargs)

Apply Barrier.

PauliFeatureMap.bind_parameters(value_dict)

Assign numeric parameters to values yielding a new circuit.

PauliFeatureMap.cast(value, _type)

Best effort to cast value to type.

PauliFeatureMap.cbit_argument_conversion(…)

Converts several classical bit representations (such as indexes, range, etc.) into a list of classical bits.

PauliFeatureMap.ccx(control_qubit1, …[, …])

Apply CCXGate.

PauliFeatureMap.ch(control_qubit, …[, …])

Apply CHGate.

PauliFeatureMap.cls_instances()

Return the current number of instances of this class, useful for auto naming.

PauliFeatureMap.cls_prefix()

Return the prefix to use for auto naming.

PauliFeatureMap.cnot(control_qubit, …[, …])

Apply CXGate.

PauliFeatureMap.combine(rhs)

Append rhs to self if self contains compatible registers.

PauliFeatureMap.compose(other[, qubits, …])

Compose circuit with other circuit or instruction, optionally permuting wires.

PauliFeatureMap.copy([name])

Copy the circuit.

PauliFeatureMap.count_ops()

Count each operation kind in the circuit.

PauliFeatureMap.crx(theta, control_qubit, …)

Apply CRXGate.

PauliFeatureMap.cry(theta, control_qubit, …)

Apply CRYGate.

PauliFeatureMap.crz(theta, control_qubit, …)

Apply CRZGate.

PauliFeatureMap.cswap(control_qubit, …[, …])

Apply CSwapGate.

PauliFeatureMap.cu1(theta, control_qubit, …)

Apply CU1Gate.

PauliFeatureMap.cu3(theta, phi, lam, …[, …])

Apply CU3Gate.

PauliFeatureMap.cx(control_qubit, …[, …])

Apply CXGate.

PauliFeatureMap.cy(control_qubit, …[, …])

Apply CYGate.

PauliFeatureMap.cz(control_qubit, …[, …])

Apply CZGate.

PauliFeatureMap.dcx(qubit1, qubit2)

Apply DCXGate.

PauliFeatureMap.decompose()

Call a decomposition pass on this circuit, to decompose one level (shallow decompose).

PauliFeatureMap.depth()

Return circuit depth (i.e., length of critical path).

PauliFeatureMap.diag_gate(diag, qubit)

Deprecated version of QuantumCircuit.diagonal.

PauliFeatureMap.diagonal(diag, qubit)

Attach a diagonal gate to a circuit.

PauliFeatureMap.draw([output, scale, …])

Draw the quantum circuit.

PauliFeatureMap.extend(rhs)

Append QuantumCircuit to the right hand side if it contains compatible registers.

PauliFeatureMap.fredkin(control_qubit, …)

Apply CSwapGate.

PauliFeatureMap.from_qasm_file(path)

Take in a QASM file and generate a QuantumCircuit object.

PauliFeatureMap.from_qasm_str(qasm_str)

Take in a QASM string and generate a QuantumCircuit object.

PauliFeatureMap.get_entangler_map(rep_num, …)

Get the entangler map for in the repetition rep_num and the block block_num.

PauliFeatureMap.get_unentangled_qubits()

Get the indices of unentangled qubits in a set.

PauliFeatureMap.h(qubit, *[, q])

Apply HGate.

PauliFeatureMap.hamiltonian(operator, time, …)

Apply hamiltonian evolution to to qubits.

PauliFeatureMap.has_register(register)

Test if this circuit has the register r.

PauliFeatureMap.i(qubit, *[, q])

Apply IGate.

PauliFeatureMap.id(qubit, *[, q])

Apply IGate.

PauliFeatureMap.iden(qubit, *[, q])

Deprecated identity gate.

PauliFeatureMap.initialize(params, qubits)

Apply initialize to circuit.

PauliFeatureMap.inverse()

Invert this circuit.

PauliFeatureMap.iso(isometry, q_input, …)

Attach an arbitrary isometry from m to n qubits to a circuit.

PauliFeatureMap.isometry(isometry, q_input, …)

Attach an arbitrary isometry from m to n qubits to a circuit.

PauliFeatureMap.iswap(qubit1, qubit2)

Apply iSwapGate.

PauliFeatureMap.mcmt(gate, control_qubits, …)

Apply a multi-control, multi-target using a generic gate.

PauliFeatureMap.mcrx(theta, q_controls, q_target)

Apply Multiple-Controlled X rotation gate

PauliFeatureMap.mcry(theta, q_controls, …)

Apply Multiple-Controlled Y rotation gate

PauliFeatureMap.mcrz(lam, q_controls, q_target)

Apply Multiple-Controlled Z rotation gate

PauliFeatureMap.mct(control_qubits, target_qubit)

Apply MCXGate.

PauliFeatureMap.mcu1(lam, control_qubits, …)

Apply MCU1Gate.

PauliFeatureMap.mcx(control_qubits, target_qubit)

Apply MCXGate.

PauliFeatureMap.measure(qubit, cbit)

Measure quantum bit into classical bit (tuples).

PauliFeatureMap.measure_active([inplace])

Adds measurement to all non-idle qubits.

PauliFeatureMap.measure_all([inplace])

Adds measurement to all qubits.

PauliFeatureMap.mirror()

Mirror the circuit by reversing the instructions.

PauliFeatureMap.ms(theta, qubits)

Apply MSGate.

PauliFeatureMap.num_connected_components([…])

How many non-entangled subcircuits can the circuit be factored to.

PauliFeatureMap.num_nonlocal_gates()

Return number of non-local gates (i.e.

PauliFeatureMap.num_tensor_factors()

Computes the number of tensor factors in the unitary (quantum) part of the circuit only.

PauliFeatureMap.num_unitary_factors()

Computes the number of tensor factors in the unitary (quantum) part of the circuit only.

PauliFeatureMap.pauli_block(pauli_string)

Get the Pauli block for the feature map circuit.

PauliFeatureMap.pauli_evolution(…)

Get the evolution block for the given pauli string.

PauliFeatureMap.print_settings()

Returns information about the setting.

PauliFeatureMap.qasm([formatted, filename])

Return OpenQASM string.

PauliFeatureMap.qbit_argument_conversion(…)

Converts several qubit representations (such as indexes, range, etc.) into a list of qubits.

PauliFeatureMap.r(theta, phi, qubit, *[, q])

Apply RGate.

PauliFeatureMap.rcccx(control_qubit1, …)

Apply RC3XGate.

PauliFeatureMap.rccx(control_qubit1, …)

Apply RCCXGate.

PauliFeatureMap.remove_final_measurements([…])

Removes final measurement on all qubits if they are present.

PauliFeatureMap.reset(qubit)

Reset q.

PauliFeatureMap.rx(theta, qubit, *[, label, q])

Apply RXGate.

PauliFeatureMap.rxx(theta, qubit1, qubit2)

Apply RXXGate.

PauliFeatureMap.ry(theta, qubit, *[, label, q])

Apply RYGate.

PauliFeatureMap.ryy(theta, qubit1, qubit2)

Apply RYYGate.

PauliFeatureMap.rz(phi, qubit, *[, q])

Apply RZGate.

PauliFeatureMap.rzx(theta, qubit1, qubit2)

Apply RZXGate.

PauliFeatureMap.rzz(theta, qubit1, qubit2)

Apply RZZGate.

PauliFeatureMap.s(qubit, *[, q])

Apply SGate.

PauliFeatureMap.sdg(qubit, *[, q])

Apply SdgGate.

PauliFeatureMap.size()

Returns total number of gate operations in circuit.

PauliFeatureMap.snapshot(label[, …])

Take a statevector snapshot of the internal simulator representation.

PauliFeatureMap.snapshot_density_matrix(label)

Take a density matrix snapshot of simulator state.

PauliFeatureMap.snapshot_expectation_value(…)

Take a snapshot of expectation value <O> of an Operator.

PauliFeatureMap.snapshot_probabilities(…)

Take a probability snapshot of the simulator state.

PauliFeatureMap.snapshot_stabilizer(label)

Take a stabilizer snapshot of the simulator state.

PauliFeatureMap.snapshot_statevector(label)

Take a statevector snapshot of the simulator state.

PauliFeatureMap.squ(unitary_matrix, qubit[, …])

Decompose an arbitrary 2*2 unitary into three rotation gates.

PauliFeatureMap.swap(qubit1, qubit2)

Apply SwapGate.

PauliFeatureMap.t(qubit, *[, q])

Apply TGate.

PauliFeatureMap.tdg(qubit, *[, q])

Apply TdgGate.

PauliFeatureMap.to_gate([parameter_map])

Create a Gate out of this circuit.

PauliFeatureMap.to_instruction([parameter_map])

Create an Instruction out of this circuit.

PauliFeatureMap.toffoli(control_qubit1, …)

Apply CCXGate.

PauliFeatureMap.u1(theta, qubit, *[, q])

Apply U1Gate.

PauliFeatureMap.u2(phi, lam, qubit, *[, q])

Apply U2Gate.

PauliFeatureMap.u3(theta, phi, lam, qubit, *)

Apply U3Gate.

PauliFeatureMap.uc(gate_list, q_controls, …)

Attach a uniformly controlled gates (also called multiplexed gates) to a circuit.

PauliFeatureMap.ucg(angle_list, q_controls, …)

Deprecated version of uc.

PauliFeatureMap.ucrx(angle_list, q_controls, …)

Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit.

PauliFeatureMap.ucry(angle_list, q_controls, …)

Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit.

PauliFeatureMap.ucrz(angle_list, q_controls, …)

Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit.

PauliFeatureMap.ucx(angle_list, q_controls, …)

Deprecated version of ucrx.

PauliFeatureMap.ucy(angle_list, q_controls, …)

Deprecated version of ucry.

PauliFeatureMap.ucz(angle_list, q_controls, …)

Deprecated version of ucrz.

PauliFeatureMap.unitary(obj, qubits[, label])

Apply unitary gate to q.

PauliFeatureMap.width()

Return number of qubits plus clbits in circuit.

PauliFeatureMap.x(qubit, *[, label, …])

Apply XGate.

PauliFeatureMap.y(qubit, *[, q])

Apply YGate.

PauliFeatureMap.z(qubit, *[, q])

Apply ZGate.

PauliFeatureMap.__getitem__(item)

Return indexed operation.

PauliFeatureMap.__len__()

Return number of operations in circuit.