Skip to main contentIBM Quantum Documentation Mirror

ZFeatureMap

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

GitHub

Bases: PauliFeatureMap

The first order Pauli Z-evolution circuit.

On 3 qubits and with 2 repetitions the circuit is represented by:

┌───┐┌─────────────┐┌───┐┌─────────────┐
┤ H ├┤ P(2.0*x[0]) ├┤ H ├┤ P(2.0*x[0]) ├
├───┤├─────────────┤├───┤├─────────────┤
┤ H ├┤ U(2.0*x[1]) ├┤ H ├┤ P(2.0*x[1]) ├
├───┤├─────────────┤├───┤├─────────────┤
┤ H ├┤ P(2.0*x[2]) ├┤ H ├┤ P(2.0*x[2]) ├
└───┘└─────────────┘└───┘└─────────────┘

This is a sub-class of PauliFeatureMap where the Pauli strings are fixed as [‘Z’]. As a result the first order expansion will be a circuit without entangling gates.

Examples

>>> prep = ZFeatureMap(3, reps=3, insert_barriers=True)
>>> print(prep.decompose())
     ┌───┐ ░ ┌─────────────┐ ░ ┌───┐ ░ ┌─────────────┐ ░ ┌───┐ ░ ┌─────────────┐
q_0: ┤ H ├─░─┤ P(2.0*x[0]) ├─░─┤ H ├─░─┤ P(2.0*x[0]) ├─░─┤ H ├─░─┤ P(2.0*x[0])
     ├───┤ ░ ├─────────────┤ ░ ├───┤ ░ ├─────────────┤ ░ ├───┤ ░ ├─────────────┤
q_1: ┤ H ├─░─┤ P(2.0*x[1]) ├─░─┤ H ├─░─┤ P(2.0*x[1]) ├─░─┤ H ├─░─┤ P(2.0*x[1])
     ├───┤ ░ ├─────────────┤ ░ ├───┤ ░ ├─────────────┤ ░ ├───┤ ░ ├─────────────┤
q_2: ┤ H ├─░─┤ P(2.0*x[2]) ├─░─┤ H ├─░─┤ P(2.0*x[2]) ├─░─┤ H ├─░─┤ P(2.0*x[2])
     └───┘ ░ └─────────────┘ ░ └───┘ ░ └─────────────┘ ░ └───┘ ░ └─────────────┘
>>> data_map = lambda x: x[0]*x[0] + 1  # note: input is an array
>>> prep = ZFeatureMap(3, reps=1, data_map_func=data_map)
>>> print(prep.decompose())
     ┌───┐┌──────────────────────┐
q_0: ┤ H ├┤ P(2.0*x[0]**2 + 2.0)
     ├───┤├──────────────────────┤
q_1: ┤ H ├┤ P(2.0*x[1]**2 + 2.0)
     ├───┤├──────────────────────┤
q_2: ┤ H ├┤ P(2.0*x[2]**2 + 2.0)
     └───┘└──────────────────────┘
>>> from qiskit.circuit.library import TwoLocal
>>> ry = TwoLocal(3, "ry", "cz", reps=1)
>>> classifier = ZFeatureMap(3, reps=1) + ry
>>> print(classifier.decompose())
     ┌───┐┌─────────────┐┌──────────┐      ┌──────────┐
q_0: ┤ H ├┤ P(2.0*x[0]) ├┤ RY(θ[0]) ├─■──■─┤ RY(θ[3]) ├────────────
     ├───┤├─────────────┤├──────────┤ │  │ └──────────┘┌──────────┐
q_1: ┤ H ├┤ P(2.0*x[1]) ├┤ RY(θ[1]) ├─■──┼──────■──────┤ RY(θ[4])
     ├───┤├─────────────┤├──────────┤    │      │      ├──────────┤
q_2: ┤ H ├┤ P(2.0*x[2]) ├┤ RY(θ[2]) ├────■──────■──────┤ RY(θ[5])
     └───┘└─────────────┘└──────────┘                  └──────────┘

Create a new first-order Pauli-Z expansion circuit.

Deprecated since version 2.1

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

Parameters

  • feature_dimension (int) – The number of features
  • reps (int) – The number of repeated circuits. Defaults to 2, has a minimum value of 1.
  • data_map_func (Callable[[ndarray], float] | None) – 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.
  • name (str) –

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