Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add calibrations with the TemplateOptimization #5752

Merged
merged 51 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8a72709
* Added fix and corresponding test to catch bug related to parameter …
eggerdj Dec 2, 2020
4592773
* Applied suggestion from cryoris.
eggerdj Dec 3, 2020
64b5fad
Merge branch 'master' of github.com:Qiskit/qiskit-terra
eggerdj Dec 15, 2020
d58ff84
Merge branch 'master' of github.com:Qiskit/qiskit-terra
eggerdj Dec 16, 2020
08df1cf
Merge branch 'master' of github.com:Qiskit/qiskit-terra
eggerdj Dec 21, 2020
173ac35
Merge branch 'master' of github.com:Qiskit/qiskit-terra
eggerdj Dec 23, 2020
cd43475
Merge branch 'master' of github.com:Qiskit/qiskit-terra
eggerdj Jan 29, 2021
6ff48b8
* Created a new TransformationPass pass CalibrationAdder to add calib…
eggerdj Jan 29, 2021
996b24c
* Cleaned-up code by using the standard RZXGate.
eggerdj Jan 30, 2021
c954f50
* Added tests.
eggerdj Jan 30, 2021
bedd931
* Moved calibration_adder to scheduling.
eggerdj Jan 30, 2021
958af81
* Added missing new line at end of file.
eggerdj Jan 30, 2021
70656cc
* Fix cyclic import.
eggerdj Jan 30, 2021
3871f13
* Added cy template.
eggerdj Jan 30, 2021
021fee7
* Added hadamards to reverse the ZX direction.
eggerdj Jan 30, 2021
e49c85a
* Fix cyclical import.
eggerdj Jan 30, 2021
2447198
* Fix tests.
eggerdj Jan 30, 2021
1d5f472
Update qiskit/transpiler/passes/scheduling/calibration_creators.py
eggerdj Jan 31, 2021
5e22d9b
Update qiskit/transpiler/passes/scheduling/calibration_adder.py
eggerdj Jan 31, 2021
3ce6a82
* Propagated the change self._calibration_adder to self._calibration_…
eggerdj Jan 31, 2021
a96335a
* Style and lint fix.
eggerdj Jan 31, 2021
8179210
* Added new template.
eggerdj Jan 31, 2021
c4f3af9
* Fixed missing import.
eggerdj Jan 31, 2021
cabbd98
Merge branch 'master' into issue-5751
eggerdj Jan 31, 2021
1bf0641
Merge branch 'master' into issue-5751
eggerdj Feb 1, 2021
38cc22e
Merge branch 'master' into issue-5751
eggerdj Feb 1, 2021
8f980eb
Update qiskit/transpiler/passes/scheduling/calibration_creators.py
eggerdj Feb 2, 2021
966f484
* Renamed ZXScheduleBuilder to RZXCalibrationBuilder.
eggerdj Feb 2, 2021
fb8e01b
* Renamed zx to rzx.
eggerdj Feb 2, 2021
4e84b70
Update qiskit/circuit/library/templates/rzx_templates.py
eggerdj Feb 2, 2021
6cdccd4
* Fixed warning message length.
eggerdj Feb 2, 2021
ec16a62
* Improved error message.
eggerdj Feb 2, 2021
4d6d8d6
* Moved rzx templates to their own files.
eggerdj Feb 2, 2021
fcf0410
* Harmonized docstrings.
eggerdj Feb 2, 2021
212cfbb
* Fixed import issue.
eggerdj Feb 2, 2021
c663b21
* Fix lint.
eggerdj Feb 2, 2021
5694ba3
* Fixed import.
eggerdj Feb 2, 2021
c3f232a
Merge branch 'master' into issue-5751
eggerdj Feb 3, 2021
7d75265
* Added binding of parameters to test_templates for templates with pa…
eggerdj Feb 3, 2021
756d61a
Update qiskit/transpiler/passes/scheduling/calibration_creators.py
eggerdj Feb 3, 2021
278e609
* Added a check to ensure that the backend has the cx gate in RZXCali…
eggerdj Feb 3, 2021
d69dce8
* Made RZXCalibrationCreator support the presence and absence of rota…
eggerdj Feb 3, 2021
c589104
* Improved class docstring of RZXCalibrationBuilder.
eggerdj Feb 4, 2021
47b63d6
* Added arxiv link to the docstring.
eggerdj Feb 4, 2021
c241286
Merge branch 'master' into issue-5751
eggerdj Feb 4, 2021
0885e89
Update qiskit/transpiler/passes/scheduling/calibration_creators.py
lcapelluto Feb 4, 2021
58251ad
* Added release note.
eggerdj Feb 8, 2021
3d5e6de
Update releasenotes/notes/issue-5751-1b6249f6263c9c30.yaml
eggerdj Feb 8, 2021
5071d2f
Merge branch 'master' into issue-5751
eggerdj Feb 9, 2021
491a880
Merge branch 'master' into issue-5751
lcapelluto Feb 9, 2021
2fa6694
Merge branch 'master' into issue-5751
mergify[bot] Feb 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions qiskit/circuit/library/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
from .nct.template_nct_9d_9 import template_nct_9d_9
from .nct.template_nct_9d_10 import template_nct_9d_10

from .rzx.rzx_yz import rzx_yz
from .rzx.rzx_xz import rzx_xz
from .rzx.rzx_cy import rzx_cy
from .rzx.rzx_zz1 import rzx_zz1
from .rzx.rzx_zz2 import rzx_zz2
from .rzx.rzx_zz3 import rzx_zz3

from .clifford.clifford_2_1 import clifford_2_1
from .clifford.clifford_2_2 import clifford_2_2
from .clifford.clifford_2_3 import clifford_2_3
Expand Down
25 changes: 25 additions & 0 deletions qiskit/circuit/library/templates/rzx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020.
#
# 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.

"""
A library of template circuits.

Templates are circuits that compute the identity. They find use
in circuit optimization where matching part of the template allows the compiler
to replace the match with the inverse of the remainder from the template.
"""
from .rzx_yz import rzx_yz
from .rzx_xz import rzx_xz
from .rzx_cy import rzx_cy
from .rzx_zz1 import rzx_zz1
from .rzx_zz2 import rzx_zz2
from .rzx_zz3 import rzx_zz3
42 changes: 42 additions & 0 deletions qiskit/circuit/library/templates/rzx/rzx_cy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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.

"""
RZX based template for CX - RYGate - CX
.. parsed-literal::
┌──────────┐
q_0: ──■─────────────■─────────────────────────────────┤0 ├───────────
┌─┴─┐┌───────┐┌─┴─┐┌────────┐┌──────────┐┌───────┐│ RZX(-ϴ) │┌─────────┐
q_1: ┤ X ├┤ RY(ϴ) ├┤ X ├┤ RY(-ϴ) ├┤ RZ(-π/2) ├┤ RX(ϴ) ├┤1 ├┤ RZ(π/2) ├
└───┘└───────┘└───┘└────────┘└──────────┘└───────┘└──────────┘└─────────┘
"""

import numpy as np
from qiskit.circuit import Parameter, QuantumCircuit


def rzx_cy(theta: float = None):
"""Template for CX - RYGate - CX."""
if theta is None:
theta = Parameter('ϴ')

circ = QuantumCircuit(2)
circ.cx(0, 1)
circ.ry(theta, 1)
circ.cx(0, 1)
circ.ry(-1*theta, 1)
circ.rz(-np.pi / 2, 1)
circ.rx(theta, 1)
circ.rzx(-1*theta, 0, 1)
circ.rz(np.pi / 2, 1)

return circ
49 changes: 49 additions & 0 deletions qiskit/circuit/library/templates/rzx/rzx_xz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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.

"""
RZX based template for CX - RXGate - CX
.. parsed-literal::
┌───┐ ┌───┐┌─────────┐┌─────────┐┌─────────┐┌──────────┐»
q_0: ┤ X ├─────────┤ X ├┤ RZ(π/2) ├┤ RX(π/2) ├┤ RZ(π/2) ├┤0 ├»
└─┬─┘┌───────┐└─┬─┘└─────────┘└─────────┘└─────────┘│ RZX(-ϴ) │»
q_1: ──■──┤ RX(ϴ) ├──■───────────────────────────────────┤1 ├»
└───────┘ └──────────┘»
« ┌─────────┐┌─────────┐┌─────────┐
«q_0: ┤ RZ(π/2) ├┤ RX(π/2) ├┤ RZ(π/2) ├
« └─────────┘└─────────┘└─────────┘
«q_1: ─────────────────────────────────
«
"""

import numpy as np
from qiskit.circuit import Parameter, QuantumCircuit


def rzx_xz(theta: float = None):
"""Template for CX - RXGate - CX."""
if theta is None:
theta = Parameter('ϴ')

qc = QuantumCircuit(2)
qc.cx(1, 0)
qc.rx(theta, 1)
qc.cx(1, 0)

qc.rz(np.pi / 2, 0)
qc.rx(np.pi / 2, 0)
qc.rz(np.pi / 2, 0)
qc.rzx(-1*theta, 0, 1)
qc.rz(np.pi / 2, 0)
qc.rx(np.pi / 2, 0)
qc.rz(np.pi / 2, 0)
return qc
40 changes: 40 additions & 0 deletions qiskit/circuit/library/templates/rzx/rzx_yz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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.

"""
RZX based template for CX - RYGate - CX
.. parsed-literal::
┌────────┐ ┌─────────┐┌─────────┐┌──────────┐
q_0: ──■──┤ RY(-ϴ) ├──■──┤ RX(π/2) ├┤0 ├┤ RX(-π/2) ├
┌─┴─┐└────────┘┌─┴─┐└─────────┘│ RZX(ϴ) │└──────────┘
q_1: ┤ X ├──────────┤ X ├───────────┤1 ├────────────
└───┘ └───┘ └─────────┘
"""

import numpy as np
from qiskit.circuit import Parameter, QuantumCircuit


def rzx_yz(theta: float = None):
"""Template for CX - RYGate - CX."""
if theta is None:
theta = Parameter('ϴ')

circ = QuantumCircuit(2)
circ.cx(0, 1)
circ.ry(-1*theta, 0)
circ.cx(0, 1)
circ.rx(np.pi / 2, 0)
circ.rzx(theta, 0, 1)
circ.rx(-np.pi / 2, 0)

return circ
64 changes: 64 additions & 0 deletions qiskit/circuit/library/templates/rzx/rzx_zz1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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.

"""
RZX based template for CX - phase - CX
.. parsed-literal::
»
q_0: ──■────────────────────────────────────────────■───────────────────────»
┌─┴─┐┌───────┐┌────┐┌───────┐┌────┐┌────────┐┌─┴─┐┌────────┐┌─────────┐»
q_1: ┤ X ├┤ RZ(ϴ) ├┤ √X ├┤ RZ(π) ├┤ √X ├┤ RZ(3π) ├┤ X ├┤ RZ(-ϴ) ├┤ RZ(π/2) ├»
└───┘└───────┘└────┘└───────┘└────┘└────────┘└───┘└────────┘└─────────┘»
« ┌──────────┐ »
«q_0: ───────────────────────────────┤0 ├──────────────────────»
« ┌─────────┐┌─────────┐┌───────┐│ RZX(-ϴ) │┌─────────┐┌─────────┐»
«q_1: ┤ RX(π/2) ├┤ RZ(π/2) ├┤ RX(ϴ) ├┤1 ├┤ RZ(π/2) ├┤ RX(π/2) ├»
« └─────────┘└─────────┘└───────┘└──────────┘└─────────┘└─────────┘»
«
«q_0: ───────────
« ┌─────────┐
«q_1: ┤ RZ(π/2) ├
« └─────────┘
"""

import numpy as np
from qiskit.circuit import Parameter, QuantumCircuit


def rzx_zz1(theta: float = None):
"""Template for CX - RZGate - CX."""
if theta is None:
theta = Parameter('ϴ')

qc = QuantumCircuit(2)
qc.cx(0, 1)
qc.rz(theta, 1)
qc.sx(1)
qc.rz(np.pi, 1)
qc.sx(1)
qc.rz(3 * np.pi, 1)
qc.cx(0, 1)
qc.rz(-1*theta, 1)

# Hadamard
qc.rz(np.pi / 2, 1)
qc.rx(np.pi / 2, 1)
qc.rz(np.pi / 2, 1)

qc.rx(theta, 1)
qc.rzx(-1*theta, 0, 1)
# Hadamard
qc.rz(np.pi / 2, 1)
qc.rx(np.pi / 2, 1)
qc.rz(np.pi / 2, 1)

return qc
54 changes: 54 additions & 0 deletions qiskit/circuit/library/templates/rzx/rzx_zz2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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.

"""
RZX based template for CX - PhaseGate - CX
.. parsed-literal::
»
q_0: ──■────────────■─────────────────────────────────────────────────────»
┌─┴─┐┌──────┐┌─┴─┐┌───────┐┌─────────┐┌─────────┐┌─────────┐┌───────┐»
q_1: ┤ X ├┤ P(ϴ) ├┤ X ├┤ P(-ϴ) ├┤ RZ(π/2) ├┤ RX(π/2) ├┤ RZ(π/2) ├┤ RX(ϴ) ├»
└───┘└──────┘└───┘└───────┘└─────────┘└─────────┘└─────────┘└───────┘»
« ┌──────────┐
«q_0: ┤0 ├─────────────────────────────────
« │ RZX(-ϴ) │┌─────────┐┌─────────┐┌─────────┐
«q_1: ┤1 ├┤ RZ(π/2) ├┤ RX(π/2) ├┤ RZ(π/2) ├
« └──────────┘└─────────┘└─────────┘└─────────┘
"""

import numpy as np
from qiskit.circuit import Parameter, QuantumCircuit


def rzx_zz2(theta: float = None):
"""Template for CX - RZGate - CX."""
if theta is None:
theta = Parameter('ϴ')

qc = QuantumCircuit(2)
qc.cx(0, 1)
qc.p(theta, 1)
qc.cx(0, 1)
qc.p(-1*theta, 1)
# Hadamard
qc.rz(np.pi / 2, 1)
qc.rx(np.pi / 2, 1)
qc.rz(np.pi / 2, 1)

qc.rx(theta, 1)
qc.rzx(-1*theta, 0, 1)
# Hadamard
qc.rz(np.pi / 2, 1)
qc.rx(np.pi / 2, 1)
qc.rz(np.pi / 2, 1)

return qc
54 changes: 54 additions & 0 deletions qiskit/circuit/library/templates/rzx/rzx_zz3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 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.

"""
RZX based template for CX - RZGate - CX
.. parsed-literal::
»
q_0: ──■─────────────■──────────────────────────────────────────────────────»
┌─┴─┐┌───────┐┌─┴─┐┌────────┐┌─────────┐┌─────────┐┌─────────┐┌───────┐»
q_1: ┤ X ├┤ RZ(ϴ) ├┤ X ├┤ RZ(-ϴ) ├┤ RZ(π/2) ├┤ RX(π/2) ├┤ RZ(π/2) ├┤ RX(ϴ) ├»
└───┘└───────┘└───┘└────────┘└─────────┘└─────────┘└─────────┘└───────┘»
« ┌──────────┐
«q_0: ┤0 ├─────────────────────────────────
« │ RZX(-ϴ) │┌─────────┐┌─────────┐┌─────────┐
«q_1: ┤1 ├┤ RZ(π/2) ├┤ RX(π/2) ├┤ RZ(π/2) ├
« └──────────┘└─────────┘└─────────┘└─────────┘
"""

import numpy as np
from qiskit.circuit import Parameter, QuantumCircuit


def rzx_zz3(theta: float = None):
"""Template for CX - RZGate - CX."""
if theta is None:
theta = Parameter('ϴ')

qc = QuantumCircuit(2)
qc.cx(0, 1)
qc.rz(theta, 1)
qc.cx(0, 1)
qc.rz(-1*theta, 1)
# Hadamard
qc.rz(np.pi / 2, 1)
qc.rx(np.pi / 2, 1)
qc.rz(np.pi / 2, 1)

qc.rx(theta, 1)
qc.rzx(-1*theta, 0, 1)
# Hadamard
qc.rz(np.pi / 2, 1)
qc.rx(np.pi / 2, 1)
qc.rz(np.pi / 2, 1)

return qc
17 changes: 17 additions & 0 deletions qiskit/dagcircuit/dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ def calibrations(self, calibrations):
"""
self._calibrations = defaultdict(dict, calibrations)

def add_calibration(self, gate, qubits, schedule, params=None):
"""Register a low-level, custom pulse definition for the given gate.

Args:
gate (Union[Gate, str]): Gate information.
qubits (Union[int, Tuple[int]]): List of qubits to be measured.
schedule (Schedule): Schedule information.
params (Optional[List[Union[float, Parameter]]]): A list of parameters.

Raises:
Exception: if the gate is of type string and params is None.
"""
if isinstance(gate, Gate):
self._calibrations[gate.name][(tuple(qubits), tuple(gate.params))] = schedule
else:
self._calibrations[gate][(tuple(qubits), tuple(params or []))] = schedule

def has_calibration_for(self, node):
"""Return True if the dag has a calibration defined for the node operation. In this
case, the operation does not need to be translated to the device basis.
Expand Down
2 changes: 2 additions & 0 deletions qiskit/transpiler/passes/scheduling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
from .alap import ALAPSchedule
from .asap import ASAPSchedule
from .time_unit_analysis import TimeUnitAnalysis
from .calibration_creators import CalibrationCreator, RZXCalibrationBuilder
from .rzx_templates import rzx_templates
Loading