Repository navigation
Labels
theme: documentationSomething is not clear or an error documentationSomething is not clear or an error documentationtheme: fault tolerancerelated to fault tolerance compilationrelated to fault tolerance compilation
Description
Environment
- Qiskit version: 49eac27
- Python version: Python 3.12.3
- Operating system: Ubuntu 24.04.4 LTS
What is happening?
$ python /tmp/bug.py
thread '<unnamed>' panicked at /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rsgridsynth-0.2.0/src/config.rs:118:14:
attempt to subtract with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
File "/tmp/bug.py", line 7, in <module>
SynthesizeRZRotations(synthesis_error=-10, cache_error=0.5)(qc)
File "/home/user/software/qiskit-venv/slot-a/src/qiskit/transpiler/basepasses.py", line 144, in __call__
out = pm.run(circuit, property_set=property_set)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/software/qiskit-venv/slot-a/src/qiskit/transpiler/passmanager.py", line 456, in wrapper
return meth(*meth_args, **meth_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/software/qiskit-venv/slot-a/src/qiskit/transpiler/passmanager.py", line 196, in run
return super().run(
^^^^^^^^^^^^
File "/home/user/software/qiskit-venv/slot-a/src/qiskit/passmanager/passmanager.py", line 238, in run
_run_workflow(
File "/home/user/software/qiskit-venv/slot-a/src/qiskit/passmanager/passmanager.py", line 313, in _run_workflow
passmanager_ir, final_state = flow_controller.execute(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/software/qiskit-venv/slot-a/src/qiskit/passmanager/base_tasks.py", line 215, in execute
passmanager_ir, state = next_task.execute(
^^^^^^^^^^^^^^^^^^
File "/home/user/software/qiskit-venv/slot-a/src/qiskit/transpiler/basepasses.py", line 167, in execute
new_dag, state = super().execute(
^^^^^^^^^^^^^^^^
File "/home/user/software/qiskit-venv/slot-a/src/qiskit/passmanager/base_tasks.py", line 97, in execute
ret = self.run(passmanager_ir)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/software/qiskit-venv/slot-a/src/qiskit/transpiler/passes/synthesis/synthesize_rz_rotations.py", line 91, in run
new_dag = synthesize_rz_rotations(
^^^^^^^^^^^^^^^^^^^^^^^^
pyo3_runtime.PanicException: attempt to subtract with overflowHow can we reproduce the issue?
from qiskit import QuantumCircuit
from qiskit.transpiler.passes.synthesis import SynthesizeRZRotations
qc = QuantumCircuit(1)
qc.rz(0.1, 0)
SynthesizeRZRotations(synthesis_error=-10, cache_error=0.5)(qc)Negative synthesis error of -9 and above will instead get a "root is complex" panic.
What should happen?
Input validation on negative synthesis error, this is invalid code.
Any suggestions?
No response
Metadata
Metadata
Assignees
Labels
theme: documentationSomething is not clear or an error documentationSomething is not clear or an error documentationtheme: fault tolerancerelated to fault tolerance compilationrelated to fault tolerance compilation
Activity
pdd23001 commentedon Jun 6, 2026
Please could I be assigned to this? Thank you!
Cryoris commentedon Jun 7, 2026
Instead of validating every possible input value, I would much prefer to clarify in the documentation that this error should be in
[0, 1]. Checking every possible input in functions decreases runtime performance and, while worthwhile in complex cases, I'd argue it's pretty clear that an error cannot be negative and that this is clearly invalid input. Nevertheless it would be good to clarify this in the docs.alexanderivrii commentedon Jun 7, 2026
Parth Danve (@pdd23001), I have assigned you. Please see the comment by Julien Gacon (@Cryoris) directly above for what you should do. Thanks for the interest to contribute.
pdd23001 commentedon Jun 7, 2026
Julien Gacon (@Cryoris) check the latest commit on the PR. I think so I have done what you requested for.
jakelishman commentedon Jul 1, 2026
Julien: we can document against this, but the root bug report is that we're panicking in Rust where we should be returning a Python-space exception. We still seem to be panicking on 2.5.0rc1, so I re-opened it if you can check?
Cryoris commentedon Jul 1, 2026
Hmm if we want to return an exception we have to explicitly check the values, don't we? I was hoping to avoid that for the overhead it comes with 🤔
jakelishman commentedon Jul 1, 2026
If you prefer to do the check in Rust space where it's cheaper, that's fine too, but
PanicExceptionis a sort of last resort from PyO3 and isn't supposedly to be handle-able - we should be emitting the error properly somehow to Python.pdd23001 commentedon Jul 6, 2026
Thanks Jake Lishman (@jakelishman), that makes sense. I'll move the fix into Rust so we return a proper Python exception instead of the PanicException.
I characterised where it actually panics so we validate the right range:
synthesis_error <= 0 panics (logarithm is not defined for 0 at exactly 0; attempt to subtract with overflow / root is complex when negative)
synthesis_error > 1 (e.g. 1.5, 2.0) does not panic
cache_error = 0, negative, or > 1 does not panic
So the only value that actually crashes is synthesis_error <= 0.
Two options for the validation-
Minimal one: guard only synthesis_error <= 0 (fixes the crash, leaves currently working inputs alone).
Strict one: enforce the documented [0, 1] range for both params, raising ValueError for anything outside it. This would also reject synthesis_error > 1 and out-of-range cache_error, which don't currently panic.
Which would you prefer?
Cryoris commentedon Jul 7, 2026
I think this needs more clarification before we can jump to action. The ranges we documented for
synthesis_errordon't seem to match gridsynth's internals, where the accuracy is measured in spectral norm difference, which can be in(0, 2]instead of(0, 1].