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

Allow backend cal to export instmap #185

Closed

Conversation

nkanazawa1989
Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 commented Jul 16, 2021

Summary

This PR allows BackendCalibrations to override instruction schedule map.
This requires Qiskit/qiskit#6759

Here is the expected usage.

my_calibration = BackendCalibrations(backend)

my_experiment = qiskit_experiments.MyExperiment(**exp_options)
# here we can set instmap-overridden backend from calibration, instead of backend above
result = my_experiment.run(my_calibration.export_backend())

Note that this framework doesn't require special logic to update calibration on experiment end.
Thus this can be applied to any kind of experiment we define.

If we want to apply custom gate

my_calibration = BackendCalibrations(backend)
basis_gates = backend.configurations().basis_gates + ["my_su4_gate"]

my_experiment = qiskit_experiments.MyExperiment(**exp_options)
my_experiment.set_transpiler_options(basis_gates=basis_gates)
result = my_experiment.run(my_calibration.export_backend(basis_gates=basis_gates))

Again, this doesn't require any custom logic. For example, we can run QV experiment with custom gates without modifying the codebase. This will add more values to the calibration module in terms of smooth integration of pulse and algorithm-level experiment.

It is noteworthy that the backend exported by the BackendCalibrations is a standard backend object. This means we can calibrate specific backend, share the experiment with the team, and let other researchers use the custom gate in other qiskit algorithm modules.

Details and comments

Copy link
Contributor

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

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

I like this approach. A test or two would be nice.

@eggerdj
Copy link
Contributor

eggerdj commented Jul 16, 2021

The one thing that this methodology along with the terra PR will not allow us to do is inject calibrations for the custom gates we created in e.g. Rabi and Drag as, e.g., an xp pulse will sometimes be tied to a gate called Rabi and sometimes to a gate called Rp. It would be nice to simplify part of the circuit builders there.

@nkanazawa1989
Copy link
Collaborator Author

Thanks @eggerdj . In experiments that may use custom gate name you always need to

backend = my_cal.export(basis_gates=["Rabi", "measure"])

exp = Rabi(qubit=0)
exp.set_transpile_options(basis_gates=["Rabi", "measure"])  # this can be overridden by self._default_transpile_options
exp.run(backend)

and it might be dynamically updated by self.set_transpile_options depending on configuration. I agree we can simplify the logic to manage gate name.

@eggerdj
Copy link
Contributor

eggerdj commented Jul 20, 2021

In experiments that may use custom gate name you always need to

backend = my_cal.export(basis_gates=["Rabi", "measure"])

exp = Rabi(qubit=0)
exp.set_transpile_options(basis_gates=["Rabi", "measure"])  # this can be overridden by self._default_transpile_options
exp.run(backend)

and it might be dynamically updated by self.set_transpile_options depending on configuration. I agree we can simplify the logic to manage gate name.

I agree with the need for basis_gates but it will miss the following situation. We have xp and x90p schedules in my_cals. Sometimes we want to run the Rabi experiment on xp and sometimes on x90p. This means we need to attach schedules with names that can change to a gate which is always called Rabi. To me it looks like we would need to do:

backend = my_cal.export(basis_gates=["Rabi", "measure"], schedule_gate_map={"xp": "Rabi"})

exp = Rabi(qubit=0)
exp.set_transpile_options(basis_gates=["Rabi", "measure"])  # this can be overridden by self._default_transpile_options
exp.run(backend)

and to use the x90p we would do

backend = my_cal.export(basis_gates=["Rabi", "measure"], schedule_gate_map={"x90p": "Rabi"})

I don't see how we get around not using something like a schedule_gate_map in the export to backend method. Note that the schedule_gate_map is optional. I.e. if you do not specify it then xp is simply xp in the inst. map. Optionally one could also consider

backend = my_cal.export(basis_gates=["Rabi", "measure"], schedule_gate_map={"x90p": ["Rabi", "x90p"]})

in case we need, for example, x90p as both a Rabi and an x90p.

@coruscating coruscating added this to the Release 0.2 milestone Aug 2, 2021
@yaelbh
Copy link
Contributor

yaelbh commented Oct 20, 2021

@nkanazawa1989 Is this PR still relevant?

@eggerdj
Copy link
Contributor

eggerdj commented Oct 20, 2021

Can we keep this open for a bit longer? There are some ideas in here that I may want to consult as I refactor the calibration experiments.

@chriseclectic chriseclectic removed this from the Release 0.3 milestone Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants