Skip to main contentIBM Quantum Documentation Mirror

ZZFeatureMap

class qiskit.circuit.library.ZZFeatureMap(feature_dimension, reps=2, entanglement='full', data_map_func=None, parameter_prefix='x', insert_barriers=False, name='ZZFeatureMap')

GitHub

Bases: PauliFeatureMap

Second-order Pauli-Z evolution circuit.

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

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

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

Examples:

from qiskit.circuit.library import ZZFeatureMap
prep = ZZFeatureMap(2, reps=1)
print(prep.decompose())
     ┌───┐┌─────────────┐
q_0: ┤ H ├┤ P(2.0*x[0]) ├──■──────────────────────────────────────■──
     ├───┤├─────────────┤┌─┴─┐┌────────────────────────────────┐┌─┴─┐
q_1: ┤ H ├┤ P(2.0*x[1]) ├┤ X ├┤ P(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├
     └───┘└─────────────┘└───┘└────────────────────────────────┘└───┘
from qiskit.circuit.library import EfficientSU2
classifier = ZZFeatureMap(3).compose(EfficientSU2(3))
classifier.num_parameters
27
classifier.parameters  # 'x' for the data preparation, 'θ' for the SU2 parameters
ParameterView([
    ParameterVectorElement(x[0]), ParameterVectorElement(x[1]),
    ParameterVectorElement(x[2]), ParameterVectorElement(θ[0]),
    ParameterVectorElement(θ[1]), ParameterVectorElement(θ[2]),
    ParameterVectorElement(θ[3]), ParameterVectorElement(θ[4]),
    ParameterVectorElement(θ[5]), ParameterVectorElement(θ[6]),
    ParameterVectorElement(θ[7]), ParameterVectorElement(θ[8]),
    ParameterVectorElement(θ[9]), ParameterVectorElement(θ[10]),
    ParameterVectorElement(θ[11]), ParameterVectorElement(θ[12]),
    ParameterVectorElement(θ[13]), ParameterVectorElement(θ[14]),
    ParameterVectorElement(θ[15]), ParameterVectorElement(θ[16]),
    ParameterVectorElement(θ[17]), ParameterVectorElement(θ[18]),
    ParameterVectorElement(θ[19]), ParameterVectorElement(θ[20]),
    ParameterVectorElement(θ[21]), ParameterVectorElement(θ[22]),
    ParameterVectorElement(θ[23])
])
classifier.count_ops()
OrderedDict([('ZZFeatureMap', 1), ('EfficientSU2', 1)])

Create a new second-order Pauli-Z expansion.

Deprecated since version 2.1

The class qiskit.circuit.library.data_preparation._zz_feature_map.ZZFeatureMap is deprecated as of Qiskit 2.1. It will be removed in Qiskit 3.0. Use the zz_feature_map function as a replacement. Note that this will no longer return a BlueprintCircuit, but just a plain QuantumCircuit.

Parameters

  • feature_dimension (int) – Number of features.
  • reps (int) – The number of repeated circuits, has a min. value of 1.
  • entanglement (str |Dict[int, List[Tuple[int]]] | Callable[[int], str |Dict[int, List[Tuple[int]]]]) – Specifies the entanglement structure. Refer to PauliFeatureMap for detail.
  • data_map_func (Callable[[ndarray], float] | None) – A mapping function for data x.
  • 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.
  • name (str) –

Raises

ValueError – If the feature dimension is smaller than 2.


Attributes

name

Type: str

A human-readable name for the circuit.

Example

from qiskit import QuantumCircuit
 
qc = QuantumCircuit(2, 2, name="my_circuit")
print(qc.name)
my_circuit