From d9f56f842491c3139864011076c028733caa08c3 Mon Sep 17 00:00:00 2001 From: Shivansh Mittal <88429611+Shivansh20128@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:43:11 +0530 Subject: [PATCH 1/2] Doc fix ZZ_feature_maps (#13231) * initial formatting changes * .compose used for concatination of two circuits * updated docstring data property * updated entanglement_blocks docstring * updated docstring of num_parameters * updates docstring of parameters * update _zz_feature_map.py documentation * update changes to ZZ_Feature_Map * update doc strings matched with parent class * _zz_feature_map.py reformatted (cherry picked from commit f1b25806e97674428b8d687bd5886f23fd6cbe80) # Conflicts: # qiskit/circuit/library/data_preparation/zz_feature_map.py --- qiskit/circuit/library/blueprintcircuit.py | 64 +++++++++++++++ .../data_preparation/pauli_feature_map.py | 5 ++ .../data_preparation/zz_feature_map.py | 77 +++++++++++++------ 3 files changed, 124 insertions(+), 22 deletions(-) diff --git a/qiskit/circuit/library/blueprintcircuit.py b/qiskit/circuit/library/blueprintcircuit.py index 16cc0e3dbafa..90550a18948e 100644 --- a/qiskit/circuit/library/blueprintcircuit.py +++ b/qiskit/circuit/library/blueprintcircuit.py @@ -94,6 +94,12 @@ def qregs(self, qregs): @property def data(self): + """The circuit data (instructions and context). + + Returns: + QuantumCircuitData: a list-like object containing the :class:`.CircuitInstruction`\\ s + for each instruction. + """ if not self._is_built: self._build() return super().data @@ -110,12 +116,70 @@ def draw(self, *args, **kwargs): @property def num_parameters(self) -> int: + """The number of parameter objects in the circuit.""" if not self._is_built: self._build() return super().num_parameters @property def parameters(self) -> ParameterView: + """The parameters defined in the circuit. + + This attribute returns the :class:`.Parameter` objects in the circuit sorted + alphabetically. Note that parameters instantiated with a :class:`.ParameterVector` + are still sorted numerically. + + Examples: + + The snippet below shows that insertion order of parameters does not matter. + + .. code-block:: python + + >>> from qiskit.circuit import QuantumCircuit, Parameter + >>> a, b, elephant = Parameter("a"), Parameter("b"), Parameter("elephant") + >>> circuit = QuantumCircuit(1) + >>> circuit.rx(b, 0) + >>> circuit.rz(elephant, 0) + >>> circuit.ry(a, 0) + >>> circuit.parameters # sorted alphabetically! + ParameterView([Parameter(a), Parameter(b), Parameter(elephant)]) + + Bear in mind that alphabetical sorting might be unintuitive when it comes to numbers. + The literal "10" comes before "2" in strict alphabetical sorting. + + .. code-block:: python + + >>> from qiskit.circuit import QuantumCircuit, Parameter + >>> angles = [Parameter("angle_1"), Parameter("angle_2"), Parameter("angle_10")] + >>> circuit = QuantumCircuit(1) + >>> circuit.u(*angles, 0) + >>> circuit.draw() + ┌─────────────────────────────┐ + q: ┤ U(angle_1,angle_2,angle_10) ├ + └─────────────────────────────┘ + >>> circuit.parameters + ParameterView([Parameter(angle_1), Parameter(angle_10), Parameter(angle_2)]) + + To respect numerical sorting, a :class:`.ParameterVector` can be used. + + .. code-block:: python + + >>> from qiskit.circuit import QuantumCircuit, Parameter, ParameterVector + >>> x = ParameterVector("x", 12) + >>> circuit = QuantumCircuit(1) + >>> for x_i in x: + ... circuit.rx(x_i, 0) + >>> circuit.parameters + ParameterView([ + ParameterVectorElement(x[0]), ParameterVectorElement(x[1]), + ParameterVectorElement(x[2]), ParameterVectorElement(x[3]), + ..., ParameterVectorElement(x[11]) + ]) + + + Returns: + The sorted :class:`.Parameter` objects in the circuit. + """ if not self._is_built: self._build() return super().parameters diff --git a/qiskit/circuit/library/data_preparation/pauli_feature_map.py b/qiskit/circuit/library/data_preparation/pauli_feature_map.py index 03bbc031ec63..da91473174af 100644 --- a/qiskit/circuit/library/data_preparation/pauli_feature_map.py +++ b/qiskit/circuit/library/data_preparation/pauli_feature_map.py @@ -209,6 +209,11 @@ def alpha(self, alpha: float) -> None: @property def entanglement_blocks(self): + """The blocks in the entanglement layers. + + Returns: + The blocks in the entanglement layers. + """ return [self.pauli_block(pauli) for pauli in self._paulis] @entanglement_blocks.setter diff --git a/qiskit/circuit/library/data_preparation/zz_feature_map.py b/qiskit/circuit/library/data_preparation/zz_feature_map.py index 5500bb6691be..1f0caebdf8f6 100644 --- a/qiskit/circuit/library/data_preparation/zz_feature_map.py +++ b/qiskit/circuit/library/data_preparation/zz_feature_map.py @@ -37,6 +37,7 @@ class ZZFeatureMap(PauliFeatureMap): Examples: +<<<<<<< HEAD:qiskit/circuit/library/data_preparation/zz_feature_map.py >>> from qiskit.circuit.library import ZZFeatureMap >>> prep = ZZFeatureMap(2, reps=1) >>> print(prep) @@ -45,30 +46,62 @@ class ZZFeatureMap(PauliFeatureMap): ├───┤├──────────────┤┌─┴─┐┌─────────────────────────────────┐┌─┴─┐ q_1: ┤ H ├┤ U1(2.0*x[1]) ├┤ X ├┤ U1(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├ └───┘└──────────────┘└───┘└─────────────────────────────────┘└───┘ +======= + .. code-block:: + + from qiskit.circuit.library import ZZFeatureMap + prep = ZZFeatureMap(2, reps=1) + print(prep.decompose()) + + .. parsed-literal:: + ┌───┐┌─────────────┐ + 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 ├ + └───┘└─────────────┘└───┘└────────────────────────────────┘└───┘ + + .. code-block:: + + from qiskit.circuit.library import EfficientSU2 + classifier = ZZFeatureMap(3).compose(EfficientSU2(3)) + classifier.num_parameters + + .. parsed-literal:: + + 27 + + .. code-block:: + + classifier.parameters # 'x' for the data preparation, 'θ' for the SU2 parameters + + .. parsed-literal:: + + 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]) + ]) + + .. code-block:: + + classifier.count_ops() + + .. parsed-literal:: +>>>>>>> f1b25806e (Doc fix ZZ_feature_maps (#13231)):qiskit/circuit/library/data_preparation/_zz_feature_map.py - >>> 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 - 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)]) + """ def __init__( From 789f00b88018b3a1ac9695f9caff48e08771e3d8 Mon Sep 17 00:00:00 2001 From: Julien Gacon Date: Thu, 3 Oct 2024 08:07:32 +0200 Subject: [PATCH 2/2] merge conflicy & other typos --- .../data_preparation/pauli_feature_map.py | 48 ++++++------- .../library/data_preparation/z_feature_map.py | 68 ++++++++++--------- .../data_preparation/zz_feature_map.py | 25 ++----- 3 files changed, 66 insertions(+), 75 deletions(-) diff --git a/qiskit/circuit/library/data_preparation/pauli_feature_map.py b/qiskit/circuit/library/data_preparation/pauli_feature_map.py index da91473174af..611c63c04b21 100644 --- a/qiskit/circuit/library/data_preparation/pauli_feature_map.py +++ b/qiskit/circuit/library/data_preparation/pauli_feature_map.py @@ -57,11 +57,11 @@ class PauliFeatureMap(NLocal): .. parsed-literal:: - ┌───┐┌──────────────┐┌──────────┐ ┌───────────┐ - ┤ 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) ├ - └───┘└──────────────┘└──────────┘└───┘└─────────────────────────────────┘└───┘└───────────┘ + ┌───┐┌─────────────┐┌──────────┐ ┌───────────┐ + ┤ H ├┤ P(2.0*x[0]) ├┤ RX(pi/2) ├──■──────────────────────────────────────■──┤ RX(-pi/2) ├ + ├───┤├─────────────┤├──────────┤┌─┴─┐┌────────────────────────────────┐┌─┴─┐├───────────┤ + ┤ H ├┤ P(2.0*x[1]) ├┤ RX(pi/2) ├┤ X ├┤ P(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├┤ RX(-pi/2) ├ + └───┘└─────────────┘└──────────┘└───┘└────────────────────────────────┘└───┘└───────────┘ The circuit contains ``reps`` repetitions of this transformation. @@ -71,37 +71,37 @@ class PauliFeatureMap(NLocal): Examples: >>> prep = PauliFeatureMap(2, reps=1, paulis=['ZZ']) - >>> print(prep) + >>> print(prep.decompose()) ┌───┐ - q_0: ┤ H ├──■───────────────────────────────────────■── - ├───┤┌─┴─┐┌─────────────────────────────────┐┌─┴─┐ - q_1: ┤ H ├┤ X ├┤ U1(2.0*(pi - x[0])*(pi - x[1])) ├┤ X ├ - └───┘└───┘└─────────────────────────────────┘└───┘ + q_0: ┤ H ├──■──────────────────────────────────────■── + ├───┤┌─┴─┐┌────────────────────────────────┐┌─┴─┐ + q_1: ┤ H ├┤ X ├┤ P(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 ├ - └───┘└──────────────┘└───┘└───┘└─────────────────────────────────┘└───┘└───┘ + >>> print(prep.decompose()) + ┌───┐┌─────────────┐┌───┐ ┌───┐ + q_0: ┤ H ├┤ P(2.0*x[0]) ├┤ H ├──■──────────────────────────────────────■──┤ H ├ + ├───┤├─────────────┤├───┤┌─┴─┐┌────────────────────────────────┐┌─┴─┐├───┤ + q_1: ┤ H ├┤ P(2.0*x[1]) ├┤ H ├┤ X ├┤ P(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 ├───────────── - └───┘ └───┘└─────────────────────────────────┘└───┘ + >>> print(prep.decompose()) + ┌───┐┌──────────┐ ┌───────────┐ + q_0: ┤ H ├┤ RX(pi/2) ├──■──────────────────────────────────────■──┤ RX(-pi/2) ├ + ├───┤└──────────┘┌─┴─┐┌────────────────────────────────┐┌─┴─┐└───────────┘ + q_1: ┤ H ├────────────┤ X ├┤ P(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 = prep.compose(wavefunction).decompose() >>> classifier.num_parameters 27 >>> classifier.count_ops() - OrderedDict([('cx', 39), ('rx', 36), ('u1', 21), ('h', 15), ('ry', 12), ('rz', 12)]) + OrderedDict([('cx', 39), ('rx', 36), ('p', 21), ('h', 15), ('ry', 12), ('rz', 12)]) References: diff --git a/qiskit/circuit/library/data_preparation/z_feature_map.py b/qiskit/circuit/library/data_preparation/z_feature_map.py index 902de1a6a5ac..a4ba32b1a0e8 100644 --- a/qiskit/circuit/library/data_preparation/z_feature_map.py +++ b/qiskit/circuit/library/data_preparation/z_feature_map.py @@ -25,13 +25,13 @@ class ZFeatureMap(PauliFeatureMap): .. parsed-literal:: - ┌───┐┌──────────────┐┌───┐┌──────────────┐ - ┤ H ├┤ U1(2.0*x[0]) ├┤ H ├┤ U1(2.0*x[0]) ├ - ├───┤├──────────────┤├───┤├──────────────┤ - ┤ H ├┤ U1(2.0*x[1]) ├┤ H ├┤ U1(2.0*x[1]) ├ - ├───┤├──────────────┤├───┤├──────────────┤ - ┤ H ├┤ U1(2.0*x[2]) ├┤ H ├┤ U1(2.0*x[2]) ├ - └───┘└──────────────┘└───┘└──────────────┘ + ┌───┐┌─────────────┐┌───┐┌─────────────┐ + ┤ H ├┤ P(2.0*x[0]) ├┤ H ├┤ P(2.0*x[0]) ├ + ├───┤├─────────────┤├───┤├─────────────┤ + ┤ H ├┤ P(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 :class:`~qiskit.circuit.library.PauliFeatureMap` where the Pauli strings are fixed as `['Z']`. As a result the first order expansion will be a circuit without @@ -39,36 +39,38 @@ class ZFeatureMap(PauliFeatureMap): Examples: + >>> from qiskit.circuit.library import ZFeatureMap >>> prep = ZFeatureMap(3, reps=3, insert_barriers=True) - >>> print(prep) - ┌───┐ ░ ┌──────────────┐ ░ ┌───┐ ░ ┌──────────────┐ ░ ┌───┐ ░ ┌──────────────┐ - q_0: ┤ H ├─░─┤ U1(2.0*x[0]) ├─░─┤ H ├─░─┤ U1(2.0*x[0]) ├─░─┤ H ├─░─┤ U1(2.0*x[0]) ├ - ├───┤ ░ ├──────────────┤ ░ ├───┤ ░ ├──────────────┤ ░ ├───┤ ░ ├──────────────┤ - q_1: ┤ H ├─░─┤ U1(2.0*x[1]) ├─░─┤ H ├─░─┤ U1(2.0*x[1]) ├─░─┤ H ├─░─┤ U1(2.0*x[1]) ├ - ├───┤ ░ ├──────────────┤ ░ ├───┤ ░ ├──────────────┤ ░ ├───┤ ░ ├──────────────┤ - q_2: ┤ H ├─░─┤ U1(2.0*x[2]) ├─░─┤ H ├─░─┤ U1(2.0*x[2]) ├─░─┤ H ├─░─┤ U1(2.0*x[2]) ├ - └───┘ ░ └──────────────┘ ░ └───┘ ░ └──────────────┘ ░ └───┘ ░ └──────────────┘ + >>> 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) - ┌───┐┌───────────────────────┐ - q_0: ┤ H ├┤ U1(2.0*x[0]**2 + 2.0) ├ - ├───┤├───────────────────────┤ - q_1: ┤ H ├┤ U1(2.0*x[1]**2 + 2.0) ├ - ├───┤├───────────────────────┤ - q_2: ┤ H ├┤ U1(2.0*x[2]**2 + 2.0) ├ - └───┘└───────────────────────┘ - - >>> classifier = ZFeatureMap(3, reps=1) + RY(3, reps=1) - >>> print(classifier) - ┌───┐┌──────────────┐┌──────────┐ ┌──────────┐ - q_0: ┤ H ├┤ U1(2.0*x[0]) ├┤ RY(θ[0]) ├─■──■─┤ RY(θ[3]) ├──────────── - ├───┤├──────────────┤├──────────┤ │ │ └──────────┘┌──────────┐ - q_1: ┤ H ├┤ U1(2.0*x[1]) ├┤ RY(θ[1]) ├─■──┼──────■──────┤ RY(θ[4]) ├ - ├───┤├──────────────┤├──────────┤ │ │ ├──────────┤ - q_2: ┤ H ├┤ U1(2.0*x[2]) ├┤ RY(θ[2]) ├────■──────■──────┤ RY(θ[5]) ├ - └───┘└──────────────┘└──────────┘ └──────────┘ + >>> 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 RealAmplitudes + >>> classifier = ZFeatureMap(3, reps=1).compose(RealAmplitudes(3, reps=1)) + >>> 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]) ├ + └───┘└─────────────┘└──────────┘ └──────────┘ """ diff --git a/qiskit/circuit/library/data_preparation/zz_feature_map.py b/qiskit/circuit/library/data_preparation/zz_feature_map.py index 1f0caebdf8f6..caf6377f691f 100644 --- a/qiskit/circuit/library/data_preparation/zz_feature_map.py +++ b/qiskit/circuit/library/data_preparation/zz_feature_map.py @@ -24,29 +24,19 @@ class ZZFeatureMap(PauliFeatureMap): .. parsed-literal:: - ┌───┐┌─────────────────┐ - ┤ 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 ├ - └───┘└─────────────────┘ └───┘└──────────────────────┘└───┘ + ┌───┐┌────────────────┐ + ┤ 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 :math:`\varphi` is a classical non-linear function, which defaults to :math:`\varphi(x) = x` if and :math:`\varphi(x,y) = (\pi - x)(\pi - y)`. Examples: -<<<<<<< HEAD:qiskit/circuit/library/data_preparation/zz_feature_map.py - >>> from qiskit.circuit.library import ZZFeatureMap - >>> prep = ZZFeatureMap(2, reps=1) - >>> 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 ├ - └───┘└──────────────┘└───┘└─────────────────────────────────┘└───┘ -======= .. code-block:: from qiskit.circuit.library import ZZFeatureMap @@ -98,7 +88,6 @@ class ZZFeatureMap(PauliFeatureMap): classifier.count_ops() .. parsed-literal:: ->>>>>>> f1b25806e (Doc fix ZZ_feature_maps (#13231)):qiskit/circuit/library/data_preparation/_zz_feature_map.py OrderedDict([('ZZFeatureMap', 1), ('EfficientSU2', 1)])