Skip to content

Commit

Permalink
merge conflicy & other typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryoris committed Oct 3, 2024
1 parent d9f56f8 commit 789f00b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 75 deletions.
48 changes: 24 additions & 24 deletions qiskit/circuit/library/data_preparation/pauli_feature_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
68 changes: 35 additions & 33 deletions qiskit/circuit/library/data_preparation/z_feature_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,52 @@ 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
entangling gates.
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]) ├
└───┘└─────────────┘└──────────┘ └──────────┘
"""

Expand Down
Loading

0 comments on commit 789f00b

Please sign in to comment.