• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Qiskit / qiskit / 13897482716
88%

Build:
DEFAULT BRANCH: main
Ran 17 Mar 2025 11:07AM UTC
Jobs 1
Files 789
Run time 41min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

17 Mar 2025 10:09AM UTC coverage: 89.552% (+1.4%) from 88.117%
13897482716

push

github

web-flow
Introduce custom sympy srepr parser (#14024)

* Introduce custom sympy srepr parser

This commit introduces a custom parser to QPY for parameter expression
payloads that were generated using sympy. Prior to QPY version 10 this
was the only way we supported serializing parameter expressions in QPY.
For QPY version 10, 11, and 12 sympy could optionally be used if the
payload was generated explicitly to not use symengine (in qiskit 1.0 it
defaulted to use symengine).
This serialization format relied on sympy to generate a string
representation of the expression which we then put in the payload. On
deserialization we called sympy's `parse_expr()` function which
internally is calling sympy's `sympify()` internally. Sympy documents
that `sympify()` relies on Python's `eval()` for string input and
should not be used with untrusted input. But `parse_expr()` didn't have
such a warning (at the time, I plan to contribute adding one), so
using this function provides an avenue for arbitrary code execution
during QPY deserialization.

This commit fixes this issue by writing a custom parser for the string
repesentation in a QPY payload based on python's ast module. This parser
walks the abstract syntax tree and builds the sympy expression object as
it it goes. It is restricted to the operations that
`ParameterExpression` supports and if any part of the string tries to
use functionality outside that set it will error.

* Simplify visitor logic

* Fix lint

* Add sanity checks that we only call sympify if coming from symengine

* Apply suggestions from code review

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

17 of 60 new or added lines in 5 files covered. (28.33%)

7 existing lines in 3 files now uncovered.

58574 of 65408 relevant lines covered (89.55%)

449982.28 hits per line

New Missed Lines in Diff

Lines Coverage ∆ File
1
91.3
-0.66% qiskit/circuit/tools/pi_check.py
2
96.74
-0.61% qiskit/circuit/parameterexpression.py
4
83.68
0.03% qiskit/qpy/binary_io/value.py
36
21.74
qiskit/qpy/binary_io/parse_sympy_repr.py

Uncovered Existing Lines

Lines Coverage ∆ File
1
94.69
0.0% crates/accelerate/src/unitary_synthesis.rs
1
94.23
-0.23% crates/qasm2/src/expr.rs
5
92.23
-0.5% crates/qasm2/src/lex.rs
Jobs
ID Job ID Ran Files Coverage
1 13897482716.1 17 Mar 2025 11:07AM UTC 789
88.07
GitHub Action Run
Source Files on build 13897482716
  • Tree
  • List 789
  • Changed 6
  • Source Changed 3
  • Coverage Changed 6
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • Github Actions Build #13897482716
  • 8bcc9f1f on github
  • Prev Build on main (#13896476661)
  • Next Build on main (#13902170881)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc