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

Update configurations to perform serialization/deserialization scalings before initializing class #4728

Merged

Conversation

taalexander
Copy link
Contributor

Summary

This fixes a bug in the mock backend data. All mock backends were updated as well. Additionally a bug was found in parametric pulse.

Details and comments

@taalexander taalexander added the bug Something isn't working label Jul 16, 2020
@taalexander taalexander requested a review from mtreinish July 16, 2020 17:05
@taalexander taalexander requested review from jyu00 and a team as code owners July 16, 2020 17:05
@@ -712,7 +712,12 @@ def convert_parametric(self, instruction):
"""
t0 = instruction.t0
channel = self.get_channel(instruction.ch)
pulse = ParametricPulseShapes[instruction.pulse_shape].value(**instruction.parameters)
parameters = instruction.parameters
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how this was working previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently this conversion was happening in the provider. It seems like this update will be required for the dumping of files. Its possible I could do this conversion in the mock backend loader @mtreinish ?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I fully follow how this gets used. But yeah we can probably port whatever we need into the fake provider class. We'll probably add a method to the base class to extract the json loading bit and PulseDefaults object creation for all the pulse backends. Right now they just all have lines like:

https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/test/mock/backends/armonk/fake_armonk.py#L55-L63

to do this. If we need to add more common code we should do that in a single place instead of multiple

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, the only thing I'm not really sure about is changing the types from the __int__ constructor I feel that is potentially a breaking change because in past releases if you did PulseBackendConfiguration(..., dt=x_in_secs)` it would now behave differently than it did in prior releases.

Also, in the past we've tried to make construction from from_dict(input) is roughly equivalent to __init__(**input) (with the exception of nested objects with to_dict/from_dict)so that regardless of how you create the objects the input is roughtly the same.

@taalexander
Copy link
Contributor Author

I'm fine moving it back. My rational was that this decouples the Python representation from the serialized representation. Thumbs up this if you want to switch back.

@mtreinish
Copy link
Member

I'm fine moving it back. My rational was that this decouples the Python representation from the serialized representation. Thumbs up this if you want to switch back.

Yeah I agree with the idea as a general statement, but I think it's potentially going to break things because it changes the input format for the constructor. So if we want to do this we should come up with a deprecation and migration plan

@taalexander
Copy link
Contributor Author

I'll revert 😄

IBM Quantum has added 3 new backends recently: Bogota, Montreal, and
Toronto. This commit creates new fake backends FakeBogota, FakeMontreal,
and FakeToronto from snapshots of the real devices.
@taalexander taalexander force-pushed the issue-4720-mock-backend-defaults-bug branch from 603d33c to 9d7c6e5 Compare July 16, 2020 22:20
@taalexander
Copy link
Contributor Author

Reverted and rebased on #4733

@taalexander taalexander requested a review from mtreinish July 16, 2020 22:21
@mtreinish mtreinish added this to the 0.15 milestone Jul 28, 2020
@mtreinish mtreinish self-assigned this Jul 28, 2020
@kdk kdk linked an issue Jul 28, 2020 that may be closed by this pull request
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

LGTM, one inline question but probably not a blocker. I was thinking it might be good to add a test for this, probably just adding some asserts to https://github.com/Qiskit/qiskit-terra/blob/master/test/python/providers/test_fake_backends.py#L78 or something to make sure we get these right moving forward.

Comment on lines +624 to +635
if self.qubit_lo_range:
out_dict['qubit_lo_range'] = [
[min_range * 1e-9, max_range * 1e-9] for
(min_range, max_range) in self.qubit_lo_range]

if self.meas_lo_range:
out_dict['meas_lo_range'] = [
[min_range * 1e-9, max_range * 1e-9] for
(min_range, max_range) in self.meas_lo_range]

if self.rep_times:
out_dict['rep_times'] = [_rt * 1e6 for _rt in self.rep_times]
Copy link
Member

Choose a reason for hiding this comment

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

How does this interact with the equivalent lines in QasmBackendConfiguration? I assume we just end up running this conversion twice and overwriting what's in out_dict with this from super().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are fields are only for pulse backends. They aren't in the QasmBackendConfiguration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ignore my previous comment. Apparently they are in the QASM backend. However, they should interact as you said so it shouldn't be an issue.

Copy link
Member

Choose a reason for hiding this comment

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

I guess the follow on question here then is whether we need this duplicated, but it doesn't hurt anything and we can always clean it up in a follow up PR later.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for adding some tests. Hopefully this means we won't have issues with the units in the fake backend snapshots moving forward.

Comment on lines +624 to +635
if self.qubit_lo_range:
out_dict['qubit_lo_range'] = [
[min_range * 1e-9, max_range * 1e-9] for
(min_range, max_range) in self.qubit_lo_range]

if self.meas_lo_range:
out_dict['meas_lo_range'] = [
[min_range * 1e-9, max_range * 1e-9] for
(min_range, max_range) in self.meas_lo_range]

if self.rep_times:
out_dict['rep_times'] = [_rt * 1e6 for _rt in self.rep_times]
Copy link
Member

Choose a reason for hiding this comment

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

I guess the follow on question here then is whether we need this duplicated, but it doesn't hurt anything and we can always clean it up in a follow up PR later.

@mergify mergify bot merged commit 3e20d3c into Qiskit:master Jul 30, 2020
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Aug 10, 2020
In Qiskit#4728 how we handle the difference between the object units and the
serialization format. However the snapshot update didn't actually save
the correct values in the json and this is causing issues for tutorials
that rely on this. This commit updates the backend snapshots for
backends by rerunning the update script to correct this issue.
mergify bot pushed a commit that referenced this pull request Aug 10, 2020
In #4728 how we handle the difference between the object units and the
serialization format. However the snapshot update didn't actually save
the correct values in the json and this is causing issues for tutorials
that rely on this. This commit updates the backend snapshots for
backends by rerunning the update script to correct this issue.
mergify bot pushed a commit that referenced this pull request Aug 10, 2020
In #4728 how we handle the difference between the object units and the
serialization format. However the snapshot update didn't actually save
the correct values in the json and this is causing issues for tutorials
that rely on this. This commit updates the backend snapshots for
backends by rerunning the update script to correct this issue.

(cherry picked from commit 0f7673e)
mergify bot added a commit that referenced this pull request Aug 10, 2020
In #4728 how we handle the difference between the object units and the
serialization format. However the snapshot update didn't actually save
the correct values in the json and this is causing issues for tutorials
that rely on this. This commit updates the backend snapshots for
backends by rerunning the update script to correct this issue.

(cherry picked from commit 0f7673e)

Co-authored-by: Matthew Treinish <[email protected]>
lcapelluto pushed a commit to lcapelluto/qiskit-terra that referenced this pull request Aug 12, 2020
In Qiskit#4728 how we handle the difference between the object units and the
serialization format. However the snapshot update didn't actually save
the correct values in the json and this is causing issues for tutorials
that rely on this. This commit updates the backend snapshots for
backends by rerunning the update script to correct this issue.
mergify bot added a commit that referenced this pull request Aug 21, 2020
* Update the qobj schema to support pulse gate calibrations.

* Fixup qobj classes: add docstrings, call out to super

* Move pulse library to top level. Fill in more details in qasm_qobj.py

* Fix mistake in schema: the pulse_library definition already contains the 'array' requirement

* Move pulse library to top level in qasm_qobj.py as well

* Add GateCalibration to qobj/__init__.py

* Fixup some implementation errors: gates contains a list of dict items, which needed to be fixed in both the schema and the py files

* Put gate calibrations into calibrations.gates to leave room for adding other metadata in the future. Make a qobj.common file to allow qobj.qasm to use features of qobj.pulse

* Add an example json

* Schema version should be referenced not hardcoded a second time

* Pretty print example file

* Check if calibrations is present when doing to from dict

* Fixup qobj test

* Update the qobj schema to support pulse gate calibrations.

* Fixup qobj classes: add docstrings, call out to super

* Move pulse library to top level. Fill in more details in qasm_qobj.py

* Fix mistake in schema: the pulse_library definition already contains the 'array' requirement

* Move pulse library to top level in qasm_qobj.py as well

* Add GateCalibration to qobj/__init__.py

* Fixup some implementation errors: gates contains a list of dict items, which needed to be fixed in both the schema and the py files

* Put gate calibrations into calibrations.gates to leave room for adding other metadata in the future. Make a qobj.common file to allow qobj.qasm to use features of qobj.pulse

* Add an example json

* Schema version should be referenced not hardcoded a second time

* Pretty print example file

* Update backend snapshots with new conf or defs (#4897)

In #4728 how we handle the difference between the object units and the
serialization format. However the snapshot update didn't actually save
the correct values in the json and this is causing issues for tutorials
that rely on this. This commit updates the backend snapshots for
backends by rerunning the update script to correct this issue.

* One reference to get_sample_pulse is raising deprecation warnings from the assembler (#4903)

* Check if calibrations is present when doing to from dict

* Fixup qobj test

* Add qobj.config.calibrations for common cals

* style

* Move recent qasm qobj changes to the new qobj.common file

* Update schema with qobj level and experiment level calibrations

* Add schema test

* Apply suggestions from code review

Co-authored-by: SooluThomas <[email protected]>

* Fix encoding for validation of new pulse library field in qasm qobj. Add qobj test

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: SooluThomas <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
ElePT pushed a commit to ElePT/qiskit-ibm-provider that referenced this pull request Oct 9, 2023
…gs before initializing class (Qiskit/qiskit#4728)

* Add fake backends for Bogota, Montreal, and Toronto

IBM Quantum has added 3 new backends recently: Bogota, Montreal, and
Toronto. This commit creates new fake backends FakeBogota, FakeMontreal,
and FakeToronto from snapshots of the real devices.

* Refactor QobjConfiguration transformations to happen in to_dict and from_dict

* Refactor PulseDefaults transformations to happen in to_dict and from_dict

* Remove conversions from update fake backends scripts.

* Update mock backends. Added ibmq_toronto and ibmq_montreal.

* fix bug in the parametric pulse code.

* Undo from_dict/init changes.

* Do conversion of complex number better.

* Update mock backend files.

* Linting.

* Add conversion tests.

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mock Backends Default values are not properly being converted back to GHz
2 participants