Skip to content

Commit

Permalink
Merge branch 'stateprep-6246' of https://github.com/javabster/qiskit-…
Browse files Browse the repository at this point in the history
…terra into stateprep-6246
  • Loading branch information
javabster committed Mar 25, 2022
2 parents 42f0e29 + b856ded commit f87f555
Show file tree
Hide file tree
Showing 38 changed files with 1,639 additions and 696 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ qpy/ @Qiskit/terra-core @nkanazawa1989
pulse/ @Qiskit/terra-core @eggerdj @nkanazawa1989 @danpuzzuoli
scheduler/ @Qiskit/terra-core @eggerdj @nkanazawa1989 @danpuzzuoli
visualization/ @Qiskit/terra-core @nonhermitian @nkanazawa1989
primitives/ @Qiskit/terra-core @ikkoham @t-imamichi
# Override the release notes directories to have _no_ code owners, so any review
# from somebody with write access is acceptable.
/releasenotes/notes
5 changes: 5 additions & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ jsonschema==3.2.0
# as we won't get matplotlib upgrades by default, this constraint likely can't
# be removed until we can unpin matplotlib.
pyparsing<3.0.0

# Jinja2 3.1.0 is incompatible with sphinx and/or jupyter until they are updated
# to work with the new jinja version (the jinja maintainers aren't going to
# fix things) pin to the previous working version.
jinja2==3.0.3
2 changes: 2 additions & 0 deletions qiskit/circuit/library/standard_gates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
RZGate
RZZGate
RZXGate
XXMinusYYGate
XXPlusYYGate
ECRGate
SGate
Expand Down Expand Up @@ -80,6 +81,7 @@
from .rz import RZGate, CRZGate
from .rzz import RZZGate
from .rzx import RZXGate
from .xx_minus_yy import XXMinusYYGate
from .xx_plus_yy import XXPlusYYGate
from .ecr import ECRGate
from .s import SGate, SdgGate
Expand Down
4 changes: 2 additions & 2 deletions qiskit/circuit/library/standard_gates/equivalence_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,13 +584,13 @@
# q_1: ┤ Sx ├ q_1: ─────┤1 ├┤ sx^0.5 ├─────
# └────┘ └───────────┘└────────┘
q = QuantumRegister(2, "q")
csx_to_zx45 = QuantumCircuit(q, global_phase=pi / 8)
csx_to_zx45 = QuantumCircuit(q, global_phase=pi / 4)
for inst, qargs, cargs in [
(XGate(), [q[0]], []),
(RZXGate(pi / 4), [q[0], q[1]], []),
(TdgGate(), [q[0]], []),
(XGate(), [q[0]], []),
(SXGate().power(0.5), [q[1]], []),
(RXGate(pi / 4), [q[1]], []),
]:
csx_to_zx45.append(inst, qargs, cargs)
_sel.add_equivalence(CSXGate(), csx_to_zx45)
Expand Down
170 changes: 170 additions & 0 deletions qiskit/circuit/library/standard_gates/xx_minus_yy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""Two-qubit XX-YY gate."""

from typing import Optional

import numpy as np

from qiskit.circuit.gate import Gate
from qiskit.circuit.library.standard_gates.ry import RYGate
from qiskit.circuit.library.standard_gates.rz import RZGate
from qiskit.circuit.library.standard_gates.s import SdgGate, SGate
from qiskit.circuit.library.standard_gates.sx import SXdgGate, SXGate
from qiskit.circuit.library.standard_gates.x import CXGate
from qiskit.circuit.parameterexpression import ParameterValueType
from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.circuit.quantumregister import QuantumRegister
from qiskit.qasm import pi


class XXMinusYYGate(Gate):
r"""XX-YY interaction gate.
A 2-qubit parameterized XX-YY interaction. Its action is to induce
a coherent rotation by some angle between :math:`|00\rangle` and :math:`|11\rangle`.
**Circuit Symbol:**
.. parsed-literal::
┌───────────────┐
q_0: ┤0 ├
│ {XX-YY}(θ,β) │
q_1: ┤1 ├
└───────────────┘
**Matrix Representation:**
.. math::
\newcommand{\th}{\frac{\theta}{2}}
R_{XX-YY}(\theta, \beta) q_0, q_1 =
RZ_1(\beta) \cdot exp(-i \frac{\theta}{2} \frac{XX-YY}{2}) \cdot RZ_1(-\beta) =
\begin{pmatrix}
\cos(\th) & 0 & 0 & -i\sin(\th)e^{-i\beta} \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
-i\sin(\th)e^{i\beta} & 0 & 0 & \cos(\th)
\end{pmatrix}
.. note::
In Qiskit's convention, higher qubit indices are more significant
(little endian convention). In the above example we apply the gate
on (q_0, q_1) which results in adding the (optional) phase defined
by :math:`beta` on q_1. Instead, if we apply it on (q_1, q_0), the
phase is added on q_0. If :math:`beta` is set to its default value
of :math:`0`, the gate is equivalent in big and little endian.
.. parsed-literal::
┌───────────────┐
q_0: ┤1 ├
│ {XX-YY}(θ,β) │
q_1: ┤0 ├
└───────────────┘
.. math::
\newcommand{\th}{\frac{\theta}{2}}
R_{XX-YY}(\theta, \beta) q_1, q_0 =
RZ_0(\beta) \cdot exp(-i \frac{\theta}{2} \frac{XX-YY}{2}) \cdot RZ_0(-\beta) =
\begin{pmatrix}
\cos(\th) & 0 & 0 & -i\sin(\th)e^{i\beta} \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
-i\sin(\th)e^{-i\beta} & 0 & 0 & \cos(\th)
\end{pmatrix}
"""

def __init__(
self,
theta: ParameterValueType,
beta: ParameterValueType = 0,
label: Optional[str] = "{XX-YY}",
):
"""Create new XX-YY gate.
Args:
theta: The rotation angle.
beta: The phase angle.
label: The label of the gate.
"""
super().__init__("xx_minus_yy", 2, [theta, beta], label=label)

def _define(self):
"""
gate xx_minus_yy(theta, beta) a, b {
rz(-beta) b;
rz(-pi/2) a;
sx a;
rz(pi/2) a;
s b;
cx a, b;
ry(theta/2) a;
ry(-theta/2) b;
cx a, b;
sdg b;
rz(-pi/2) a;
sxdg a;
rz(pi/2) a;
rz(beta) b;
}
"""
theta, beta = self.params
register = QuantumRegister(2, "q")
circuit = QuantumCircuit(register, name=self.name)
a, b = register
rules = [
(RZGate(-beta), [b], []),
(RZGate(-pi / 2), [a], []),
(SXGate(), [a], []),
(RZGate(pi / 2), [a], []),
(SGate(), [b], []),
(CXGate(), [a, b], []),
(RYGate(theta / 2), [a], []),
(RYGate(-theta / 2), [b], []),
(CXGate(), [a, b], []),
(SdgGate(), [b], []),
(RZGate(-pi / 2), [a], []),
(SXdgGate(), [a], []),
(RZGate(pi / 2), [a], []),
(RZGate(beta), [b], []),
]
for instr, qargs, cargs in rules:
circuit._append(instr, qargs, cargs)

self.definition = circuit

def inverse(self):
"""Inverse gate."""
theta, beta = self.params
return XXMinusYYGate(-theta, beta)

def __array__(self, dtype=None):
"""Gate matrix."""
theta, beta = self.params
cos = np.cos(theta / 2)
sin = np.sin(theta / 2)
return np.array(
[
[cos, 0, 0, -1j * sin * np.exp(-1j * beta)],
[0, 1, 0, 0],
[0, 0, 1, 0],
[-1j * sin * np.exp(1j * beta), 0, 0, cos],
],
dtype=dtype,
)
4 changes: 4 additions & 0 deletions qiskit/transpiler/basepasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ def __call__(self, circuit, property_set=None):

if self.property_set["layout"]:
result_circuit._layout = self.property_set["layout"]
if self.property_set["clbit_write_latency"] is not None:
result_circuit._clbit_write_latency = self.property_set["clbit_write_latency"]
if self.property_set["conditional_latency"] is not None:
result_circuit._conditional_latency = self.property_set["conditional_latency"]

return result_circuit

Expand Down
8 changes: 7 additions & 1 deletion qiskit/transpiler/passes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@
ALAPSchedule
ASAPSchedule
DynamicalDecoupling
ConstrainedReschedule
AlignMeasures
ValidatePulseGates
InstructionDurationCheck
SetIOLatency
Circuit Analysis
================
Expand Down Expand Up @@ -227,9 +230,12 @@
from .scheduling import ALAPSchedule
from .scheduling import ASAPSchedule
from .scheduling import DynamicalDecoupling
from .scheduling import AlignMeasures
from .scheduling import AlignMeasures # Deprecated
from .scheduling import ValidatePulseGates
from .scheduling import PadDelay
from .scheduling import ConstrainedReschedule
from .scheduling import InstructionDurationCheck
from .scheduling import SetIOLatency

# additional utility passes
from .utils import CheckMap
Expand Down
Loading

0 comments on commit f87f555

Please sign in to comment.