-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ECR gate and approximation_degree option (#5609)
* add approximate decomposition * add echo cross-resonance gate (ECR) * add FakeJohannesburgECR * modify fake_johannesburg_ecr basis_gates * fix circ.ecr() method * update direction fixing passes to work on ecr as well * level 3: optimize after direction fixup * add synthesis_fidelity to UnitarySynthesis and ensure ConsolidateBlocks emits unitaries * fix cx->ecr translation global phase * keep level3 structure as before * lint * releasenote * rename passes from cx to gate * fix deprecation warning * ensure we stay in basis after gate direction * lint * circular import * minor fixes * synthesis_fidelity -> approximation_degree * approximation degree in UnitarySynthesis * style * add tests * lint * Update test/python/compiler/test_transpiler.py Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com> Co-authored-by: Kevin Krsulich <kevin@krsulich.net> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a568893
commit 346ffa8
Showing
26 changed files
with
609 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ | |
RZGate | ||
RZZGate | ||
RZXGate | ||
ECRGate | ||
SGate | ||
SdgGate | ||
SwapGate | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2017, 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 ZX-rotation gate.""" | ||
|
||
import numpy as np | ||
|
||
from qiskit.circuit.gate import Gate | ||
from qiskit.circuit.quantumregister import QuantumRegister | ||
from .rzx import RZXGate | ||
from .x import XGate | ||
|
||
|
||
class ECRGate(Gate): | ||
r"""An echoed RZX(pi/2) gate implemented using RZX(pi/4) and RZX(-pi/4). | ||
This gate is maximally entangling and is equivalent to a CNOT up to | ||
single-qubit pre-rotations. The echoing procedure mitigates some | ||
unwanted terms (terms other than ZX) to cancel in an experiment. | ||
**Circuit Symbol:** | ||
.. parsed-literal:: | ||
┌─────────┐ ┌────────────┐┌────────┐┌─────────────┐ | ||
q_0: ┤0 ├ q_0: ┤0 ├┤ RX(pi) ├┤0 ├ | ||
│ ECR │ = │ RZX(pi/4) │└────────┘│ RZX(-pi/4) │ | ||
q_1: ┤1 ├ q_1: ┤1 ├──────────┤1 ├ | ||
└─────────┘ └────────────┘ └─────────────┘ | ||
**Matrix Representation:** | ||
.. math:: | ||
ECR\ q_0, q_1 = \frac{1}{\sqrt{2}} | ||
\begin{pmatrix} | ||
0 & 1 & 0 & i \\ | ||
1 & 0 & -i & 0 \\ | ||
0 & i & 0 & 1 \\ | ||
-i & 0 & 1 & 0 | ||
\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 the :math:`X \otimes Z` tensor order. | ||
Instead, if we apply it on (q_1, q_0), the matrix will | ||
be :math:`Z \otimes X`: | ||
.. parsed-literal:: | ||
┌─────────┐ | ||
q_0: ┤1 ├ | ||
│ ECR │ | ||
q_1: ┤0 ├ | ||
└─────────┘ | ||
.. math:: | ||
ECR\ q_0, q_1 = \frac{1}{\sqrt{2}} | ||
\begin{pmatrix} | ||
0 & 0 & 1 & i \\ | ||
0 & 0 & i & 1 \\ | ||
1 & -i & 0 & 0 \\ | ||
-i & 1 & 0 & 0 | ||
\end{pmatrix} | ||
""" | ||
|
||
def __init__(self): | ||
"""Create new ECR gate.""" | ||
super().__init__('ecr', 2, []) | ||
|
||
def _define(self): | ||
""" | ||
gate ecr a, b { rzx(pi/4) a, b; x a; rzx(-pi/4) a, b;} | ||
""" | ||
# pylint: disable=cyclic-import | ||
from qiskit.circuit.quantumcircuit import QuantumCircuit | ||
q = QuantumRegister(2, 'q') | ||
qc = QuantumCircuit(q, name=self.name) | ||
rules = [ | ||
(RZXGate(np.pi/4), [q[0], q[1]], []), | ||
(XGate(), [q[0]], []), | ||
(RZXGate(-np.pi/4), [q[0], q[1]], []) | ||
] | ||
for instr, qargs, cargs in rules: | ||
qc._append(instr, qargs, cargs) | ||
|
||
self.definition = qc | ||
|
||
def to_matrix(self): | ||
"""Return a numpy.array for the ECR gate.""" | ||
return 1/np.sqrt(2) * \ | ||
np.array([[0, 1, 0, 1.j], | ||
[1, 0, -1.j, 0], | ||
[0, 1.j, 0, 1], | ||
[-1.j, 0, 1, 0]], dtype=complex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.