ZZFeatureMap¶

class ZZFeatureMap(feature_dimension, reps=2, entanglement='full', data_map_func=None, insert_barriers=False)[source]

Second-order Pauli-Z evolution circuit.

For 3 qubits and 1 repetition and linear entanglement the circuit is represented by:

```┌───┐┌─────────────────┐
┤ H ├┤ U1(2.0*φ(x[0])) ├──■────────────────────────────■────────────────────────────────────
├───┤├─────────────────┤┌─┴─┐┌──────────────────────┐┌─┴─┐
┤ H ├┤ U1(2.0*φ(x[1])) ├┤ X ├┤ U1(2.0*φ(x[0],x[1])) ├┤ X ├──■────────────────────────────■──
├───┤├─────────────────┤└───┘└──────────────────────┘└───┘┌─┴─┐┌──────────────────────┐┌─┴─┐
┤ H ├┤ U1(2.0*φ(x[2])) ├──────────────────────────────────┤ X ├┤ U1(2.0*φ(x[1],x[2])) ├┤ X ├
└───┘└─────────────────┘                                  └───┘└──────────────────────┘└───┘
```

where `φ` is a classical non-linear function, which defaults to `φ(x) = x` if and `φ(x,y) = (pi - x)(pi - y)`.

Examples

```>>> prep = ZZFeatureMap(2, reps=2)
>>> print(prep)
┌───┐┌──────────────┐
q_0: ┤ H ├┤ U1(2.0*x[0]) ├──■───────────────────────────────────────■──
├───┤├──────────────┤┌─┴─┐┌─────────────────────────────────┐┌─┴─┐
q_1: ┤ H ├┤ U1(2.0*x[1]) ├┤ X ├┤ U1(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├
└───┘└──────────────┘└───┘└─────────────────────────────────┘└───┘
```
```>>> from qiskit.circuit.library import EfficientSU2
>>> classifier = ZZFeatureMap(3) + EfficientSU2(3)
>>> classifier.num_parameters
15
>>> classifier.parameters  # 'x' for the data preparation, 'θ' for the SU2 parameters
{Parameter(θ[9]), Parameter(θ[4]), Parameter(θ[6]), Parameter(θ[1]), Parameter(x[2]),
Parameter(θ[7]), Parameter(x[1]), Parameter(θ[8]), Parameter(θ[2]), Parameter(θ[10]),
Parameter(θ[5]), Parameter(θ[0]), Parameter(θ[3]), Parameter(x[0]), Parameter(θ[11])}
>>> classifier.count_ops()
OrderedDict([('u1', 12), ('cx', 12), ('ry', 12), ('cz', 9), ('h', 6)])
```

Create a new second-order Pauli-Z expansion.

Parameters
• feature_dimension (`int`) – Number of features.

• reps (`int`) – The number of repeated circuits, has a min. value of 1.

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

• data_map_func (`Optional`[`Callable`[[`ndarray`], `float`]]) – A mapping function for data x.

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

Attributes

 `ZZFeatureMap.clbits` Returns a list of classical bits in the order that the registers were added. `ZZFeatureMap.data` Return the circuit data (instructions and context). `ZZFeatureMap.entanglement` Get the entanglement strategy. `ZZFeatureMap.entanglement_blocks` The blocks in the entanglement layers. `ZZFeatureMap.extension_lib` `ZZFeatureMap.feature_dimension` Returns the feature dimension (which is equal to the number of qubits). `ZZFeatureMap.header` `ZZFeatureMap.initial_state` Return the initial state that is added in front of the n-local circuit. `ZZFeatureMap.insert_barriers` If barriers are inserted in between the layers or not. `ZZFeatureMap.instances` `ZZFeatureMap.n_qubits` Deprecated, use `num_qubits` instead. `ZZFeatureMap.num_clbits` Return number of classical bits. `ZZFeatureMap.num_layers` Return the number of layers in the n-local circuit. `ZZFeatureMap.num_parameters` Convenience function to get the number of parameter objects in the circuit. `ZZFeatureMap.num_parameters_settable` The number of distinct parameters. `ZZFeatureMap.num_qubits` Returns the number of qubits in this circuit. `ZZFeatureMap.ordered_parameters` The parameters used in the underlying circuit. `ZZFeatureMap.parameter_bounds` The parameter bounds for the unbound parameters in the circuit. `ZZFeatureMap.parameters` Get the `Parameter` objects in the circuit. `ZZFeatureMap.paulis` The Pauli strings used in the entanglement of the qubits. `ZZFeatureMap.preferred_init_points` The initial points for the parameters. `ZZFeatureMap.prefix` `ZZFeatureMap.qregs` A list of the quantum registers associated with the circuit. `ZZFeatureMap.qubits` Returns a list of quantum bits in the order that the registers were added. `ZZFeatureMap.reps` The number of times rotation and entanglement block are repeated. `ZZFeatureMap.rotation_blocks` The blocks in the rotation layers.

Methods

 `ZZFeatureMap.AND`(qr_variables, qb_target, …) Build a collective conjunction (AND) circuit in place using mct. `ZZFeatureMap.OR`(qr_variables, qb_target, …) Build a collective disjunction (OR) circuit in place using mct. Return indexed operation. Return number of operations in circuit. `ZZFeatureMap.add_layer`(other[, …]) Append another layer to the NLocal. Add registers. `ZZFeatureMap.append`(instruction[, qargs, cargs]) Append one or more instructions to the end of the circuit, modifying the circuit in place. `ZZFeatureMap.assign_parameters`(param_dict[, …]) Assign parameters to the n-local circuit. `ZZFeatureMap.barrier`(*qargs) Apply `Barrier`. `ZZFeatureMap.bind_parameters`(value_dict) Assign numeric parameters to values yielding a new circuit. `ZZFeatureMap.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. `ZZFeatureMap.ccx`(control_qubit1, …[, …]) Apply `CCXGate`. `ZZFeatureMap.ch`(control_qubit, target_qubit, *) Apply `CHGate`. Return the current number of instances of this class, useful for auto naming. Return the prefix to use for auto naming. `ZZFeatureMap.cnot`(control_qubit, target_qubit, *) Apply `CXGate`. Append rhs to self if self contains compatible registers. `ZZFeatureMap.compose`(other[, qubits, …]) Compose circuit with `other` circuit or instruction, optionally permuting wires. `ZZFeatureMap.copy`([name]) Copy the circuit. Count each operation kind in the circuit. `ZZFeatureMap.crx`(theta, control_qubit, …) Apply `CRXGate`. `ZZFeatureMap.cry`(theta, control_qubit, …) Apply `CRYGate`. `ZZFeatureMap.crz`(theta, control_qubit, …) Apply `CRZGate`. `ZZFeatureMap.cswap`(control_qubit, …[, …]) Apply `CSwapGate`. `ZZFeatureMap.cu1`(theta, control_qubit, …) Apply `CU1Gate`. `ZZFeatureMap.cu3`(theta, phi, lam, …[, …]) Apply `CU3Gate`. `ZZFeatureMap.cx`(control_qubit, target_qubit, *) Apply `CXGate`. `ZZFeatureMap.cy`(control_qubit, target_qubit, *) Apply `CYGate`. `ZZFeatureMap.cz`(control_qubit, target_qubit, *) Apply `CZGate`. `ZZFeatureMap.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). `ZZFeatureMap.diag_gate`(diag, qubit) Deprecated version of QuantumCircuit.diagonal. `ZZFeatureMap.diagonal`(diag, qubit) Attach a diagonal gate to a circuit. `ZZFeatureMap.draw`([output, scale, filename, …]) Draw the quantum circuit. Append QuantumCircuit to the right hand side if it contains compatible registers. `ZZFeatureMap.fredkin`(control_qubit, …[, …]) Apply `CSwapGate`. Take in a QASM file and generate a QuantumCircuit object. `ZZFeatureMap.from_qasm_str`(qasm_str) Take in a QASM string and generate a QuantumCircuit object. `ZZFeatureMap.get_entangler_map`(rep_num, …) Get the entangler map for in the repetition `rep_num` and the block `block_num`. Get the indices of unentangled qubits in a set. `ZZFeatureMap.h`(qubit, *[, q]) Apply `HGate`. `ZZFeatureMap.hamiltonian`(operator, time, qubits) Apply hamiltonian evolution to to qubits. `ZZFeatureMap.has_register`(register) Test if this circuit has the register r. `ZZFeatureMap.i`(qubit, *[, q]) Apply `IGate`. `ZZFeatureMap.id`(qubit, *[, q]) Apply `IGate`. `ZZFeatureMap.iden`(qubit, *[, q]) Deprecated identity gate. `ZZFeatureMap.initialize`(params, qubits) Apply initialize to circuit. Invert this circuit. `ZZFeatureMap.iso`(isometry, q_input, …[, …]) Attach an arbitrary isometry from m to n qubits to a circuit. `ZZFeatureMap.isometry`(isometry, q_input, …) Attach an arbitrary isometry from m to n qubits to a circuit. `ZZFeatureMap.iswap`(qubit1, qubit2) Apply `iSwapGate`. `ZZFeatureMap.mcmt`(gate, control_qubits, …) Apply a multi-control, multi-target using a generic gate. `ZZFeatureMap.mcrx`(theta, q_controls, q_target) Apply Multiple-Controlled X rotation gate `ZZFeatureMap.mcry`(theta, q_controls, …[, …]) Apply Multiple-Controlled Y rotation gate `ZZFeatureMap.mcrz`(lam, q_controls, q_target) Apply Multiple-Controlled Z rotation gate `ZZFeatureMap.mct`(control_qubits, target_qubit) Apply `MCXGate`. `ZZFeatureMap.mcu1`(lam, control_qubits, …) Apply `MCU1Gate`. `ZZFeatureMap.mcx`(control_qubits, target_qubit) Apply `MCXGate`. `ZZFeatureMap.measure`(qubit, cbit) Measure quantum bit into classical bit (tuples). `ZZFeatureMap.measure_active`([inplace]) Adds measurement to all non-idle qubits. `ZZFeatureMap.measure_all`([inplace]) Adds measurement to all qubits. Mirror the circuit by reversing the instructions. `ZZFeatureMap.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. `ZZFeatureMap.pauli_block`(pauli_string) Get the Pauli block for the feature map circuit. `ZZFeatureMap.pauli_evolution`(pauli_string, time) Get the evolution block for the given pauli string. Returns information about the setting. `ZZFeatureMap.qasm`([formatted, filename]) Return OpenQASM string. Converts several qubit representations (such as indexes, range, etc.) into a list of qubits. `ZZFeatureMap.r`(theta, phi, qubit, *[, q]) Apply `RGate`. `ZZFeatureMap.rcccx`(control_qubit1, …) Apply `RC3XGate`. `ZZFeatureMap.rccx`(control_qubit1, …) Apply `RCCXGate`. Removes final measurement on all qubits if they are present. `ZZFeatureMap.reset`(qubit) Reset q. `ZZFeatureMap.rx`(theta, qubit, *[, label, q]) Apply `RXGate`. `ZZFeatureMap.rxx`(theta, qubit1, qubit2) Apply `RXXGate`. `ZZFeatureMap.ry`(theta, qubit, *[, label, q]) Apply `RYGate`. `ZZFeatureMap.ryy`(theta, qubit1, qubit2) Apply `RYYGate`. `ZZFeatureMap.rz`(phi, qubit, *[, q]) Apply `RZGate`. `ZZFeatureMap.rzx`(theta, qubit1, qubit2) Apply `RZXGate`. `ZZFeatureMap.rzz`(theta, qubit1, qubit2) Apply `RZZGate`. `ZZFeatureMap.s`(qubit, *[, q]) Apply `SGate`. `ZZFeatureMap.sdg`(qubit, *[, q]) Apply `SdgGate`. Returns total number of gate operations in circuit. `ZZFeatureMap.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 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. `ZZFeatureMap.squ`(unitary_matrix, qubit[, …]) Decompose an arbitrary 2*2 unitary into three rotation gates. `ZZFeatureMap.swap`(qubit1, qubit2) Apply `SwapGate`. `ZZFeatureMap.t`(qubit, *[, q]) Apply `TGate`. `ZZFeatureMap.tdg`(qubit, *[, q]) Apply `TdgGate`. `ZZFeatureMap.to_gate`([parameter_map]) Create a Gate out of this circuit. `ZZFeatureMap.to_instruction`([parameter_map]) Create an Instruction out of this circuit. `ZZFeatureMap.toffoli`(control_qubit1, …[, …]) Apply `CCXGate`. `ZZFeatureMap.u1`(theta, qubit, *[, q]) Apply `U1Gate`. `ZZFeatureMap.u2`(phi, lam, qubit, *[, q]) Apply `U2Gate`. `ZZFeatureMap.u3`(theta, phi, lam, qubit, *[, q]) Apply `U3Gate`. `ZZFeatureMap.uc`(gate_list, q_controls, q_target) Attach a uniformly controlled gates (also called multiplexed gates) to a circuit. `ZZFeatureMap.ucg`(angle_list, q_controls, …) Deprecated version of uc. `ZZFeatureMap.ucrx`(angle_list, q_controls, …) Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit. `ZZFeatureMap.ucry`(angle_list, q_controls, …) Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit. `ZZFeatureMap.ucrz`(angle_list, q_controls, …) Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit. `ZZFeatureMap.ucx`(angle_list, q_controls, …) Deprecated version of ucrx. `ZZFeatureMap.ucy`(angle_list, q_controls, …) Deprecated version of ucry. `ZZFeatureMap.ucz`(angle_list, q_controls, …) Deprecated version of ucrz. `ZZFeatureMap.unitary`(obj, qubits[, label]) Apply unitary gate to q. Return number of qubits plus clbits in circuit. `ZZFeatureMap.x`(qubit, *[, label, ctrl_state, q]) Apply `XGate`. `ZZFeatureMap.y`(qubit, *[, q]) Apply `YGate`. `ZZFeatureMap.z`(qubit, *[, q]) Apply `ZGate`. Return indexed operation. Return number of operations in circuit.