Skip to main content
IBM Quantum Platform
This page is from the dev version of Qiskit SDK. Go to the stable version.

qiskit.circuit.library.z_feature_map

qiskit.circuit.library.z_feature_map(feature_dimension, reps=2, entanglement='full', alpha=2.0, data_map_func=None, parameter_prefix='x', insert_barriers=False, name='ZFeatureMap')

GitHub

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.

Parameters

  • feature_dimension (int) – Number of qubits in the circuit.
  • reps (int) – The number of times the evolution layers are repeated.
  • entanglement (str |Sequence[Sequence[int]] | Callable[[int], str |Sequence[Sequence[int]]]) – Specifies the entanglement structure. Can be a string ('full', 'linear', 'reverse_linear', 'circular' or 'sca'), a list of integer-tuples, or a callable returning these types for each repetition.
  • alpha (float) – The Pauli rotation factor, multiplicative to the pauli rotations.
  • data_map_func (Callable[[Parameter], ParameterExpression] | None) – A mapping function for the data x which can be supplied to override the default mapping.
  • 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) – The name of the circuit.

Returns

A quantum circuit implementing the Z feature map.

Return type

QuantumCircuit

Examples

>>> from qiskit.circuit.library import z_feature_map
>>> prep = z_feature_map(3, reps=3, insert_barriers=True)
>>> print(prep)
     ┌───┐ ░ ┌─────────────┐ ░ ┌───┐ ░ ┌─────────────┐ ░ ┌───┐ ░ ┌─────────────┐
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 = z_feature_map(3, reps=1, data_map_func=data_map)
>>> print(prep)
     ┌───┐┌──────────────────────┐
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 n_local
>>> circuit = n_local(3, "ry", "cz", reps=1).decompose()
>>> classifier = z_feature_map(3, reps=1)
>>> classifier.append(circuit, list(range(classifier.num_qubits)))
>>> print(classifier)
     ┌───┐┌─────────────┐┌──────────┐      ┌──────────┐
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])
     └───┘└─────────────┘└──────────┘                  └──────────┘
Was this page helpful?
Report a bug, typo, or request content on GitHub.