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

Handle huge integers in OpenQASM 2 expression evaluator #12140

Merged
merged 2 commits into from
May 14, 2024

Conversation

jakelishman
Copy link
Member

Summary

This modifies the expression evaluator to directly parse the backing string data of an integer token in a floating-point context, which lets us handle numbers that would otherwise overflow a usize. It's possible for this to be totally valid, if, for example, the integer is a multiple of some very large power of two that doesn't overflow a double-precision float.

We already needed to immediately cast the integer to a float, so this is just a more accurate way of doing the evaluation, and doesn't affect when we use integers in other contexts.

Details and comments

Fix #11561

This modifies the expression evaluator to directly parse the backing
string data of an integer token in a floating-point context, which lets
us handle numbers that would otherwise overflow a `usize`.  It's
possible for this to be totally valid, if, for example, the integer is a
multiple of some very large power of two that doesn't overflow a
double-precision float.

We already needed to immediately cast the integer to a float, so this is
just a more accurate way of doing the evaluation, and doesn't affect
when we use integers in other contexts.
@jakelishman jakelishman 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: qasm2 Relating to OpenQASM 2 import or export labels Apr 4, 2024
@jakelishman jakelishman added this to the 1.0.3 milestone Apr 4, 2024
@jakelishman jakelishman requested a review from a team as a code owner April 4, 2024 15:58
@qiskit-bot
Copy link
Collaborator

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

@coveralls
Copy link

coveralls commented Apr 5, 2024

Pull Request Test Coverage Report for Build 8646868413

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 2 files are covered.
  • 584 unchanged lines in 54 files lost coverage.
  • Overall coverage decreased (-0.01%) to 89.369%

Files with Coverage Reduction New Missed Lines %
qiskit/synthesis/evolution/qdrift.py 1 93.55%
qiskit/circuit/store.py 1 94.29%
qiskit/circuit/parameter.py 1 98.39%
qiskit/circuit/library/blueprintcircuit.py 2 95.16%
qiskit/primitives/backend_estimator_v2.py 2 97.84%
qiskit/circuit/library/generalized_gates/rv.py 2 85.71%
qiskit/circuit/library/arithmetic/quadratic_form.py 2 97.01%
qiskit/circuit/library/standard_gates/u.py 2 97.8%
qiskit/synthesis/unitary/qsd.py 2 97.54%
qiskit/synthesis/two_qubit/xx_decompose/decomposer.py 2 90.63%
Totals Coverage Status
Change from base Build 8554012050: -0.01%
Covered Lines: 60308
Relevant Lines: 67482

💛 - Coveralls

crates/qasm2/src/lex.rs Outdated Show resolved Hide resolved
crates/qasm2/src/expr.rs Outdated Show resolved Hide resolved
@mtreinish mtreinish modified the milestones: 1.0.3, 1.1.0 May 14, 2024
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 for the changes!

@kevinhartman kevinhartman added this pull request to the merge queue May 14, 2024
Merged via the queue into Qiskit:main with commit fe69594 May 14, 2024
12 checks passed
mergify bot pushed a commit that referenced this pull request May 14, 2024
* Handle huge integers in OpenQASM 2 expression evaluator

This modifies the expression evaluator to directly parse the backing
string data of an integer token in a floating-point context, which lets
us handle numbers that would otherwise overflow a `usize`.  It's
possible for this to be totally valid, if, for example, the integer is a
multiple of some very large power of two that doesn't overflow a
double-precision float.

We already needed to immediately cast the integer to a float, so this is
just a more accurate way of doing the evaluation, and doesn't affect
when we use integers in other contexts.

* Clarify int/float split

(cherry picked from commit fe69594)
@jakelishman jakelishman deleted the qasm2/float-context branch May 14, 2024 16:23
@jakelishman
Copy link
Member Author

@Mergifyio backport stable/0.46

Copy link
Contributor

mergify bot commented May 14, 2024

backport stable/0.46

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 14, 2024
* Handle huge integers in OpenQASM 2 expression evaluator

This modifies the expression evaluator to directly parse the backing
string data of an integer token in a floating-point context, which lets
us handle numbers that would otherwise overflow a `usize`.  It's
possible for this to be totally valid, if, for example, the integer is a
multiple of some very large power of two that doesn't overflow a
double-precision float.

We already needed to immediately cast the integer to a float, so this is
just a more accurate way of doing the evaluation, and doesn't affect
when we use integers in other contexts.

* Clarify int/float split

(cherry picked from commit fe69594)
github-merge-queue bot pushed a commit that referenced this pull request May 14, 2024
)

* Handle huge integers in OpenQASM 2 expression evaluator

This modifies the expression evaluator to directly parse the backing
string data of an integer token in a floating-point context, which lets
us handle numbers that would otherwise overflow a `usize`.  It's
possible for this to be totally valid, if, for example, the integer is a
multiple of some very large power of two that doesn't overflow a
double-precision float.

We already needed to immediately cast the integer to a float, so this is
just a more accurate way of doing the evaluation, and doesn't affect
when we use integers in other contexts.

* Clarify int/float split

(cherry picked from commit fe69594)

Co-authored-by: Jake Lishman <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request May 14, 2024
)

* Handle huge integers in OpenQASM 2 expression evaluator

This modifies the expression evaluator to directly parse the backing
string data of an integer token in a floating-point context, which lets
us handle numbers that would otherwise overflow a `usize`.  It's
possible for this to be totally valid, if, for example, the integer is a
multiple of some very large power of two that doesn't overflow a
double-precision float.

We already needed to immediately cast the integer to a float, so this is
just a more accurate way of doing the evaluation, and doesn't affect
when we use integers in other contexts.

* Clarify int/float split

(cherry picked from commit fe69594)

Co-authored-by: Jake Lishman <[email protected]>
ElePT pushed a commit to ElePT/qiskit that referenced this pull request May 31, 2024
* Handle huge integers in OpenQASM 2 expression evaluator

This modifies the expression evaluator to directly parse the backing
string data of an integer token in a floating-point context, which lets
us handle numbers that would otherwise overflow a `usize`.  It's
possible for this to be totally valid, if, for example, the integer is a
multiple of some very large power of two that doesn't overflow a
double-precision float.

We already needed to immediately cast the integer to a float, so this is
just a more accurate way of doing the evaluation, and doesn't affect
when we use integers in other contexts.

* Clarify int/float split
jakelishman added a commit to jakelishman/qiskit-terra that referenced this pull request Jul 15, 2024
We fixed handling of giant integers in gate expression positions
Qiskitgh-12140, and this commit fixes the handling in conditionals.
Unfortunately, this means pulling in big-int handling properly; the
integers simply _are_ bigints, and we're not immediately converting them
into something else.

The need to support this may influence how the Rust-space data models of
`QuantumCircuit` evolve.
github-merge-queue bot pushed a commit that referenced this pull request Jul 30, 2024
* Fix parsing of huge OpenQASM 2 conditionals

We fixed handling of giant integers in gate expression positions
gh-12140, and this commit fixes the handling in conditionals.
Unfortunately, this means pulling in big-int handling properly; the
integers simply _are_ bigints, and we're not immediately converting them
into something else.

The need to support this may influence how the Rust-space data models of
`QuantumCircuit` evolve.

* Move `num-bigint` dependency to workspace
mergify bot pushed a commit that referenced this pull request Jul 30, 2024
* Fix parsing of huge OpenQASM 2 conditionals

We fixed handling of giant integers in gate expression positions
gh-12140, and this commit fixes the handling in conditionals.
Unfortunately, this means pulling in big-int handling properly; the
integers simply _are_ bigints, and we're not immediately converting them
into something else.

The need to support this may influence how the Rust-space data models of
`QuantumCircuit` evolve.

* Move `num-bigint` dependency to workspace

(cherry picked from commit 85f9860)

# Conflicts:
#	Cargo.toml
#	crates/accelerate/Cargo.toml
mergify bot pushed a commit that referenced this pull request Jul 30, 2024
* Fix parsing of huge OpenQASM 2 conditionals

We fixed handling of giant integers in gate expression positions
gh-12140, and this commit fixes the handling in conditionals.
Unfortunately, this means pulling in big-int handling properly; the
integers simply _are_ bigints, and we're not immediately converting them
into something else.

The need to support this may influence how the Rust-space data models of
`QuantumCircuit` evolve.

* Move `num-bigint` dependency to workspace

(cherry picked from commit 85f9860)
jakelishman added a commit that referenced this pull request Jul 30, 2024
* Fix parsing of huge OpenQASM 2 conditionals

We fixed handling of giant integers in gate expression positions
gh-12140, and this commit fixes the handling in conditionals.
Unfortunately, this means pulling in big-int handling properly; the
integers simply _are_ bigints, and we're not immediately converting them
into something else.

The need to support this may influence how the Rust-space data models of
`QuantumCircuit` evolve.

* Move `num-bigint` dependency to workspace

(cherry picked from commit 85f9860)
github-merge-queue bot pushed a commit that referenced this pull request Jul 30, 2024
* Fix parsing of huge OpenQASM 2 conditionals

We fixed handling of giant integers in gate expression positions
gh-12140, and this commit fixes the handling in conditionals.
Unfortunately, this means pulling in big-int handling properly; the
integers simply _are_ bigints, and we're not immediately converting them
into something else.

The need to support this may influence how the Rust-space data models of
`QuantumCircuit` evolve.

* Move `num-bigint` dependency to workspace

(cherry picked from commit 85f9860)

Co-authored-by: Jake Lishman <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Jul 30, 2024
* Fix parsing of huge OpenQASM 2 conditionals

We fixed handling of giant integers in gate expression positions
gh-12140, and this commit fixes the handling in conditionals.
Unfortunately, this means pulling in big-int handling properly; the
integers simply _are_ bigints, and we're not immediately converting them
into something else.

The need to support this may influence how the Rust-space data models of
`QuantumCircuit` evolve.

* Move `num-bigint` dependency to workspace

(cherry picked from commit 85f9860)

Co-authored-by: Jake Lishman <[email protected]>
Procatv pushed a commit to Procatv/qiskit-terra-catherines that referenced this pull request Aug 1, 2024
* Fix parsing of huge OpenQASM 2 conditionals

We fixed handling of giant integers in gate expression positions
Qiskitgh-12140, and this commit fixes the handling in conditionals.
Unfortunately, this means pulling in big-int handling properly; the
integers simply _are_ bigints, and we're not immediately converting them
into something else.

The need to support this may influence how the Rust-space data models of
`QuantumCircuit` evolve.

* Move `num-bigint` dependency to workspace
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: qasm2 Relating to OpenQASM 2 import or export 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.

PanicException: called Result::unwrap() on an Err value: ParseIntError { kind: PosOverflow }
5 participants