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 toZZFeatureMap
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.
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 toNLocal
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 fromself_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
Returns a list of classical bits in the order that the registers were added.
Return the circuit data (instructions and context).
Get the entanglement strategy.
The blocks in the entanglement layers.
Returns the feature dimension (which is equal to the number of qubits).
Return the initial state that is added in front of the n-local circuit.
If barriers are inserted in between the layers or not.
Deprecated, use
num_qubits
instead.Return number of classical bits.
Return the number of layers in the n-local circuit.
Convenience function to get the number of parameter objects in the circuit.
The number of distinct parameters.
Returns the number of qubits in this circuit.
The parameters used in the underlying circuit.
The parameter bounds for the unbound parameters in the circuit.
Get the
Parameter
objects in the circuit.The Pauli strings used in the entanglement of the qubits.
The initial points for the parameters.
A list of the quantum registers associated with the circuit.
Returns a list of quantum bits in the order that the registers were added.
The number of times rotation and entanglement block are repeated.
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.
Return indexed operation.
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.
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
.Return the current number of instances of this class, useful for auto naming.
Return the prefix to use for auto naming.
PauliFeatureMap.cnot
(control_qubit, …[, …])Apply
CXGate
.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.
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
.Call a decomposition pass on this circuit, to decompose one level (shallow decompose).
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.
Append QuantumCircuit to the right hand side if it contains compatible registers.
PauliFeatureMap.fredkin
(control_qubit, …)Apply
CSwapGate
.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 blockblock_num
.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.
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.
Mirror the circuit by reversing the instructions.
PauliFeatureMap.ms
(theta, qubits)Apply
MSGate
.How many non-entangled subcircuits can the circuit be factored to.
Return number of non-local gates (i.e.
Computes the number of tensor factors in the unitary (quantum) part of the circuit only.
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.
Get the evolution block for the given pauli string.
Returns information about the setting.
PauliFeatureMap.qasm
([formatted, filename])Return OpenQASM string.
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
.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
.Returns total number of gate operations in circuit.
PauliFeatureMap.snapshot
(label[, …])Take a statevector snapshot of the internal simulator representation.
Take a density matrix snapshot of simulator state.
Take a snapshot of expectation value <O> of an Operator.
Take a probability snapshot of the simulator state.
Take a stabilizer snapshot of the simulator state.
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.
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
.Return indexed operation.
Return number of operations in circuit.