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

Add calibrations with the TemplateOptimization #5752

merged 51 commits into from
Feb 11, 2021

Conversation

eggerdj
Copy link
Contributor

@eggerdj eggerdj commented Jan 29, 2021

Summary

TemplateOptimization can be used to match templates in a quantum circuit and replace them with more efficient gate decompositions. This PR implements #5751 by providing a library of ZX-based templates and provides a new transpilation pass (named CalibrationAdder) to add the corresponding schedules (i.e. calibrations) generated from a subclass of the new abstract base class CalibrationCreator.

Details and comments

An illustrative example of this functionality can be run through the self contained code

from qiskit import QuantumCircuit, transpile, schedule, IBMQ

from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import TemplateOptimization

# New contributions to the template optimization
from qiskit.transpiler.passes.scheduling import RZXCalibrationBuilder, rzx_templates

IBMQ.load_account()
provider = IBMQ.get_provider(...)

backend = provider.get_backend('ibmq_athens')


qc = QuantumCircuit(2)
qc.cx(0,1)
qc.p(0.12, 1)
qc.cx(0,1)
print('Original circuit:')
print(qc)

pass_ = TemplateOptimization(**rzx_templates(['zz2']))
qc_cz = PassManager(pass_).run(qc)
print('ZX based circuit:')
print(qc_cz)

# Add the calibrations
pass_ = RZXCalibrationBuilder(backend)
cal_qc = PassManager(pass_).run(qc_cz)

# Transpile to the backend basis gates
cal_qct = transpile(cal_qc, backend)
qct = transpile(qc, backend)

# Compare the schedule durations
print('Duration of schedule with the calibration:')
print(schedule(cal_qct, backend).duration)
print('Duration of standard with two CNOT gates:')
print(schedule(qct, backend).duration)

The output of this code (see below) shows that there is a significant reduction in schedule duration when using the native ZX interaction of the backend. In this exmaple, the pulse schedule of the unitary is generated from the instruction schedule map of the backend.

Original circuit:
                          
q_0: ──■───────────────■──
     ┌─┴─┐┌─────────┐┌─┴─┐
q_1: ┤ X ├┤ P(0.12) ├┤ X ├
     └───┘└─────────┘└───┘
ZX based circuit:
                                         ┌────────────┐             »
q_0: ────────────────────────────────────┤1           ├─────────────»
     ┌──────────┐┌──────────┐┌──────────┐│  RZX(0.12) │┌───────────┐»
q_1: ┤ RZ(-π/2) ├┤ RX(-π/2) ├┤ RZ(-π/2) ├┤0           ├┤ RX(-0.12) ├»
     └──────────┘└──────────┘└──────────┘└────────────┘└───────────┘»
«                                                    
«q_0: ───────────────────────────────────────────────
«     ┌──────────┐┌──────────┐┌──────────┐┌─────────┐
«q_1: ┤ RZ(-π/2) ├┤ RX(-π/2) ├┤ RZ(-π/2) ├┤ P(0.12) ├
«     └──────────┘└──────────┘└──────────┘└─────────┘
Duration of schedule with the calibration:
1472
Duration of standard with two CNOT gates:
3712

…rations to a quantum circuit.

* Created a new abstract base class CalibrationCreator that is given to CalibrationAdder
  - CalibrationCreator is capable of telling if it supports a given DAG node.
  - If a DAG node is supported then it can create a calibration for that node and taylored to the backend.
* Created a child class of CalibrationCreator to build ZX schedules based on ECR gates.
* Created the library zx templates which provides ZX-based templates for the TemplateOptimizer.
* Added the method add_calibration to DAGCircuit.
* Amended corresponding __init__ files.
@eggerdj eggerdj requested a review from a team as a code owner January 29, 2021 22:46
@eggerdj eggerdj self-assigned this Jan 29, 2021
@eggerdj eggerdj changed the title [WIP] Add calibrations with the TemplateOptimization Add calibrations with the TemplateOptimization Jan 30, 2021
lcapelluto
lcapelluto previously approved these changes Feb 3, 2021
Copy link
Contributor

@lcapelluto lcapelluto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I didn't look closely at the templates, but it seems like those are tested to be the identify, which should be sufficient, yes?

@eggerdj
Copy link
Contributor Author

eggerdj commented Feb 4, 2021

Yes, the templates are tested to be the identity. Since these are parametric it requires assigning a value to the parameter. In the tests this value is 0.2 which is not some special value such as pi/2.

lcapelluto
lcapelluto previously approved these changes Feb 4, 2021
@eggerdj eggerdj requested a review from ajavadia February 5, 2021 14:33
ajavadia
ajavadia previously approved these changes Feb 8, 2021
@eggerdj eggerdj dismissed stale reviews from ajavadia and lcapelluto via 58251ad February 8, 2021 21:20
@lcapelluto lcapelluto added Changelog: New Feature Include in the "Added" section of the changelog automerge labels Feb 8, 2021
lcapelluto
lcapelluto previously approved these changes Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants