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 version flag to qpy dump #11644

Merged
merged 9 commits into from Jan 31, 2024
Merged

Conversation

mtreinish
Copy link
Member

Summary

This commit adds a new keyword argument to the qpy.dump() function which is used to specify a compatibility version of QPY which is the latest version for the 0.45 and 0.46 version. This basically adds a compatibility mode for generating QPY files that returns a fixed QPY version that enables the 0.45 and 0.46 release to load the QPY files generated with the 1.0 release. The default output doesn't change and dump() will always return the latest QPY format version by default as this is the version that gets all the bugfixes and is kept up to date with the QuantumCircuit class.

As of this commit the compatibility version and the latest version are the same, both at version 10. However, this flag is being added so that the interface exists for when we inevitably need to update the QPY version field for any release in the 1.x major version series. There are potential PRs in the 1.0 release series that will bump the latest QPY version to 11 which will change this and those PRs will need to factor this in when they change the format.

Details and comments

This commit adds a new keyword argument to the qpy.dump() function which
is used to specify a compatibility version of QPY which is the latest
version for the 0.45 and 0.46 version. This basically adds a compatibility
mode for generating QPY files that returns a fixed QPY version that
enables the 0.45 and 0.46 release to load the QPY files generated with
the 1.0 release. The default output doesn't change and dump() will
always return the latest QPY format version by default as this is the
version that gets all the bugfixes and is kept up to date with the
QuantumCircuit class.

As of this commit the compatibility version and the latest version are
the same, both at version 10. However, this flag is being added so that
the interface exists for when we inevitably need to update the QPY
version field for any release in the 1.x major version series. There are
potential PRs in the 1.0 release series that will bump the latest QPY
version to 11 which will change this and those PRs will need to factor
this in when they change the format.
@mtreinish mtreinish added Changelog: New Feature Include in the "Added" section of the changelog mod: qpy Related to QPY serialization labels Jan 25, 2024
@mtreinish mtreinish added this to the 1.0.0 milestone Jan 25, 2024
@mtreinish mtreinish requested a review from a team as a code owner January 25, 2024 17:34
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @mtreinish
  • @nkanazawa1989

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

I think this is something that we absolutely do need to maintain the stability goals of the 1.x series, and consequently something we should accept a feature-freeze exception for.

@@ -76,6 +78,7 @@ def dump(
file_obj: BinaryIO,
metadata_serializer: Optional[Type[JSONEncoder]] = None,
use_symengine: bool = True,
version: int | None = None,
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it's worth setting this directly as version: int = 10, and us just changing that default on minor releases (if appropriate)? I'm not sure if allowing None buys us anything, and using the value directly makes it appear more obviously in things like documentation and help.

Copy link
Member Author

Choose a reason for hiding this comment

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

I specifically want the default to always be the latest version. I'm fine with making the default explicit, but I would prefer version: int = common.QPY_VERSION so that we are always tracking it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in: 2b90f67

Copy link
Member

Choose a reason for hiding this comment

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

I think the edge case I have in mind is if we have to release a new QPY format in a patch release, but we still want the default to be fixed for the minor release.

If we elect that bugs requiring a QPY format change aren't eligible for backport, then I agree with using the CURRENT_VERSION flag, otherwise I prefer a separate DEFAULT_VERSION attribute, but I don't feel too strongly.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think not allowing QPY format changes in bugfix releases makes the most sense for a few reasons. I hadn't considered decoupling the latest and default for a potential backport scenario that's an interesting idea. But I'm not sure even then we'd want to allow backports to patch releases because to me it increases the complexity of the backport and increases the risk of making the change.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, in general I agree with this, it's just not hitherto been our practice. If we want to change the policy to this for 1.0+ I'm on board.

Comment on lines 132 to 137
version: The QPY format version to emit. By default this defaults to
the latest supported format (which is currently 10), however for
compatibility reasons if you need to load the generated QPY payload with an older version
of Qiskit you can also select the minimum supported export version, which only can change
during a Qiskit major version release, to generate an older QPY format version. As of this
major release series the minimum supported export version is version 10.
Copy link
Member

Choose a reason for hiding this comment

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

If we changed the default to just be an int, we wouldn't need to comment on the "this is currently 10" bit, which I'm almost certain we'll forget to update next time we change it.

We might want to expose the minimum supported export version as a data attribute on the qiskit.qpy module (e.g. qiskit.qpy.MINIMUM_DUMP_VERSION = 10) so it can be queried programmatically and so we can just point to that in the docs and have that sentence autoupdate as well. (tbh, we probably want qiskit.qpy.CURRENT_VERSION as well)

Copy link
Member Author

Choose a reason for hiding this comment

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

qpy.common.QPY_VERSION is the equivalent of what qiskit.qpy.CURRENT_VERSION would be. But we can rexport it and add a module attribute easily enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in: 2b90f67

Copy link
Contributor

Choose a reason for hiding this comment

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

Now version=10 shows up in the signature in the API docs, but I think it would be good to add QPY_VERSION and QPY_COMPATIBILITY_VERSION to the API docs as well, and possibly reference them instead of writing 10 in the docstring here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added it to the api docs here: 2d38739 and removed the use of 10 in the docstring here in: 600bb9c

@coveralls
Copy link

coveralls commented Jan 25, 2024

Pull Request Test Coverage Report for Build 7716962098

Warning: This coverage report may be inaccurate.

We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
To ensure accuracy in future PRs, please see these guidelines.
A quick fix for this PR: rebase it; your next report should be accurate.

  • 0 of 7 (100.0%) changed or added relevant lines in 3 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.002%) to 89.572%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 6 91.94%
Totals Coverage Status
Change from base Build 7716480517: 0.002%
Covered Lines: 59545
Relevant Lines: 66477

💛 - Coveralls

qiskit/qpy/interface.py Show resolved Hide resolved
test/python/qpy/test_circuit_load_from_qpy.py Outdated Show resolved Hide resolved
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Thanks for this, Matt. I think the provider team will be happy to see this change, and I'm hoping that the larger team we have around Qiskit now will keep the extended support manageable.

@jakelishman jakelishman added this pull request to the merge queue Jan 31, 2024
Merged via the queue into Qiskit:main with commit 3b82fea Jan 31, 2024
12 checks passed
@mtreinish mtreinish deleted the qpy-version-negotiation branch January 31, 2024 11:00
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 mod: qpy Related to QPY serialization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants