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

Track QuantumCircuit.global_phase in ParameterTable #11428

Merged
merged 3 commits into from
Dec 20, 2023

Conversation

jakelishman
Copy link
Member

Summary

We have previously always had a split where circuit parameters used in instructions were tracked in the ParameterTable, but any parameters used in the global phase were not. Any method that influenced the parameters needed to separately check the global phase, and merge that information with that in the ParameterTable. This made it easy to forget, or easy for the handling of it to become out of sync.

This commit now tracks the global phase as part of the ParameterTable, so this object is now the canonical source of parameter information for the circuit (outside the context of calibrations, which are handled entirely separately). The ParameterTable is an internal detail, and only accessible through private attributes, so is not part of the public interface.

Details and comments

Dependent on #11109, which this PR currently includes. I'll rebase it after that merges, but I'm putting this up a little early just to have things to link to in the dependency chain of #7107.

No changelog because it's a dev-only internal detail (in theory).

@jakelishman jakelishman added Changelog: None Do not include in changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Dec 18, 2023
@jakelishman jakelishman added this to the 1.0.0 milestone Dec 18, 2023
@jakelishman jakelishman requested a review from a team as a code owner December 18, 2023 17:45
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Dec 18, 2023

Pull Request Test Coverage Report for Build 7280677428

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.

  • 37 of 45 (82.22%) changed or added relevant lines in 2 files are covered.
  • 104 unchanged lines in 5 files lost coverage.
  • Overall coverage decreased (-0.02%) to 87.536%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/circuit/quantumcircuit.py 26 27 96.3%
qiskit/circuit/parametertable.py 11 18 61.11%
Files with Coverage Reduction New Missed Lines %
qiskit/circuit/library/standard_gates/u3.py 1 98.9%
qiskit/circuit/bit.py 3 91.49%
crates/qasm2/src/lex.rs 7 91.16%
crates/accelerate/src/quantum_circuit/circuit_data.rs 8 90.71%
qiskit/circuit/quantumcircuit.py 85 91.39%
Totals Coverage Status
Change from base Build 7263539836: -0.02%
Covered Lines: 59174
Relevant Lines: 67600

💛 - Coveralls

We have previously always had a split where circuit parameters used in
instructions were tracked in the `ParameterTable`, but any parameters
used in the global phase were not.  Any method that influenced the
parameters needed to separately check the global phase, and merge that
information with that in the `ParameterTable`.  This made it easy to
forget, or easy for the handling of it to become out of sync.

This commit now tracks the global phase as part of the `ParameterTable`,
so this object is now the canonical source of parameter information for
the circuit (outside the context of calibrations, which are handled
entirely separately).  The `ParameterTable` is an internal detail, and
only accessible through private attributes, so is not part of the public
interface.
@jakelishman
Copy link
Member Author

Now rebased over #11109.

ElePT
ElePT previously approved these changes Dec 19, 2023
Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

From my (less limited than a few hours ago, but still limited) understanding, I don't see any functional issue with this implementation. It might not be the most straightforward, manual intervention is needed in a few points to make sure that the global phase is tracked properly (for example in copy), and this is adding responsibility to the developers (to keep on top of these details). But at the same time, I cannot come up with any concrete feedback or suggestions to improve it. I will approve to make sure this PR is not blocked, but it might be worth having somebody else give it some thought too.

@jakelishman
Copy link
Member Author

Yeah, that's pretty much how I felt writing it as well, haha. I don't like what I've done hugely, but I don't have any better ideas, and overall this makes parameter-handling code more local.

kevinhartman
kevinhartman previously approved these changes Dec 20, 2023
Copy link
Contributor

@kevinhartman kevinhartman 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'll need to update #11214 once this merges to handle parameter remapping in circuit_to_instruction.

Approving but holding off on merge in case addressing my comment warrants any code change. Feel free to merge as is.

qiskit/circuit/quantumcircuit.py Outdated Show resolved Hide resolved
@jakelishman jakelishman dismissed stale reviews from kevinhartman and ElePT via 31009c9 December 20, 2023 20:45
Copy link
Contributor

@kevinhartman kevinhartman 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants