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 support for QuantumCircuit.layout to qpy #10148

Merged
merged 32 commits into from
Jul 7, 2023

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented May 23, 2023

Summary

This commit adds the missing support for QuantumCircuit.layout to the qpy format. This necessitates bumping the QPY format version to 8 to accommodate the extra data needed for representing the details of the layout. The tricky piece with representing the 3 TranspileLayout attributes is representing the virtual bits in the initial layout because there is no guarantee that the input circuit's registers are in the output circuit (typically they are not when transpile() is used).

Details and comments

TODO:

  • Finish documentation
  • Add backwards compatibility tests
  • Add test coverage for layout with standalone qubits (no associated register)
  • Add release note

Fixes #10112

This commit adds the missing support for QuantumCircuit.layout to the
qpy format. This necessitates bumping the QPY format version to 8 to
accomodate the extra data needed for representing the details of the
layout. The tricky piece with representing the 3 TranspileLayout
attributes is representing the virtual bits in the initial layout
because there is no guarantee that the input circuit's registers are in
the output circuit (typically they are not when transpile() is used).

Fixes Qiskit#10112
@mtreinish mtreinish added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qpy Related to QPY serialization labels May 23, 2023
@mtreinish mtreinish added this to the 0.24.1 milestone May 23, 2023
@mtreinish mtreinish requested a review from a team as a code owner May 23, 2023 22:09
@qiskit-bot
Copy link
Collaborator

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

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

@coveralls
Copy link

coveralls commented May 24, 2023

Pull Request Test Coverage Report for Build 5489994589

  • 96 of 98 (97.96%) changed or added relevant lines in 3 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 86.0%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/qpy/binary_io/circuits.py 89 91 97.8%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 1 91.65%
qiskit/extensions/quantum_initializer/squ.py 2 80.0%
Totals Coverage Status
Change from base Build 5488180890: 0.02%
Covered Lines: 71650
Relevant Lines: 83314

💛 - Coveralls

@mtreinish mtreinish changed the title [WIP] Add support for QuantumCircuit.layout to qpy Add support for QuantumCircuit.layout to qpy May 24, 2023
qiskit/qpy/__init__.py Outdated Show resolved Hide resolved
qiskit/qpy/__init__.py Outdated Show resolved Hide resolved
@jlapeyre jlapeyre mentioned this pull request May 31, 2023
4 tasks
qiskit/qpy/__init__.py Outdated Show resolved Hide resolved
@kdk kdk modified the milestones: 0.24.1, 0.24.2 Jun 1, 2023
qiskit/qpy/__init__.py Outdated Show resolved Hide resolved
@mtreinish mtreinish mentioned this pull request Jun 19, 2023
jakelishman
jakelishman previously approved these changes Jul 7, 2023
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.

One mostly nit-pick comment, but otherwise I'm still happy with the state of this.

#10392 will need updating after this PR merges to fix documentation conflicts only, but that's not a big deal.

test/python/qpy/test_circuit_load_from_qpy.py Outdated Show resolved Hide resolved
@jakelishman jakelishman added this pull request to the merge queue Jul 7, 2023
Merged via the queue into Qiskit:main with commit dbf1230 Jul 7, 2023
14 checks passed
mergify bot pushed a commit that referenced this pull request Jul 7, 2023
* Add support for QuantumCircuit.layout to qpy

This commit adds the missing support for QuantumCircuit.layout to the
qpy format. This necessitates bumping the QPY format version to 8 to
accomodate the extra data needed for representing the details of the
layout. The tricky piece with representing the 3 TranspileLayout
attributes is representing the virtual bits in the initial layout
because there is no guarantee that the input circuit's registers are in
the output circuit (typically they are not when transpile() is used).

Fixes #10112

* Fix handling of empty layout

* Expand test coverage

* Fix lint

* Add qpy compat tests

* Fix compat tests

* Add release notes

* Adjust layout creation to be register independent

* Finish docs

* Only check layout in compat tests with circuits

* Fix typos

* Fix doc typo in qiskit/qpy/__init__.py

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>

* Adjust introduction version for layout qpy compat tests

* Unify qpy compat test version filter style

* Add new line to layout error message

* Simplify serialization logic

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

* Doc fixes

* Improve test coverage

* Don't reuse bits between initial layout and circuit in qpy compat tests.

* Update qiskit/qpy/__init__.py

* Fix test typo

* Use a register in compat tests for consistent equality

* Update test/python/qpy/test_circuit_load_from_qpy.py

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
(cherry picked from commit dbf1230)
github-merge-queue bot pushed a commit that referenced this pull request Jul 10, 2023
* Add support for QuantumCircuit.layout to qpy

This commit adds the missing support for QuantumCircuit.layout to the
qpy format. This necessitates bumping the QPY format version to 8 to
accomodate the extra data needed for representing the details of the
layout. The tricky piece with representing the 3 TranspileLayout
attributes is representing the virtual bits in the initial layout
because there is no guarantee that the input circuit's registers are in
the output circuit (typically they are not when transpile() is used).

Fixes #10112

* Fix handling of empty layout

* Expand test coverage

* Fix lint

* Add qpy compat tests

* Fix compat tests

* Add release notes

* Adjust layout creation to be register independent

* Finish docs

* Only check layout in compat tests with circuits

* Fix typos

* Fix doc typo in qiskit/qpy/__init__.py

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>

* Adjust introduction version for layout qpy compat tests

* Unify qpy compat test version filter style

* Add new line to layout error message

* Simplify serialization logic

Co-authored-by: Jake Lishman <jake.lishman@ibm.com>

* Doc fixes

* Improve test coverage

* Don't reuse bits between initial layout and circuit in qpy compat tests.

* Update qiskit/qpy/__init__.py

* Fix test typo

* Use a register in compat tests for consistent equality

* Update test/python/qpy/test_circuit_load_from_qpy.py

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
(cherry picked from commit dbf1230)

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog mod: qpy Related to QPY serialization stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QPy roundtripping discards physical qubit information on circuit
6 participants