qiskit
qiskit copied to clipboard
Remove stale `variable_class_operations` set from `Target`
NOTE This is a refactored PR since the cause of the errors was found to be a different reason.
I will leave the old description attached, the following description is only valid for commits after 0caa7d5e2375310b7a468b20a51bd66c7dd610cc
Summary
Fixes #12953
The following commits remove a stale attribute of the rust target called variable_class_operations which was used to keep track of all the variadics within the target but was not kept during the serialization step.
Details and comments:
When performing serialization, we were forgetting to include variable_class_operations set of names in the state mapping. Since the nature of TargetOperation is to work as an enum of either Instruction instances or class aliases that would represent Variadic instructions. The usage of that structure was redundant, so it was removed.
The following changes were made:
num_qubitsreturns an instance ofu32, callers will need to make sure they're dealing with aNormalOperation.paramsbehaves more similarly, returning a slice ofParaminstances. Will panic if called on aVariadicoperation.
A test case was added to check for something similar to what was mentioned by @doichanj in #12953.
Old description
The following commit ensures that when the `num_qubits` or `params` are extracted from a variadic, we always return `None`.
### Details and comments
- The `num_qubits` property for `TargetOperation` returns an `Option<u32>` instead of panicking in the case that the instruction is a `Variadic`.
- The `params` property for `TargetOperation` returns an `Option<[&Param]>]` instance instead of panicking in the case of a `Variadic`.
One or more of the following people are relevant to this code:
@Qiskit/terra-core@kevinhartman@mtreinish
Pull Request Test Coverage Report for Build 11333770906
Details
- 22 of 28 (78.57%) changed or added relevant lines in 1 file are covered.
- 25 unchanged lines in 5 files lost coverage.
- Overall coverage decreased (-0.004%) to 88.658%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| crates/accelerate/src/target_transpiler/mod.rs | 22 | 28 | 78.57% |
| <!-- | Total: | 22 | 28 |
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| qiskit/transpiler/passes/synthesis/unitary_synthesis.py | 2 | 88.19% |
| crates/qasm2/src/lex.rs | 3 | 92.48% |
| crates/qasm2/src/parse.rs | 6 | 97.15% |
| qiskit/synthesis/two_qubit/xx_decompose/decomposer.py | 6 | 90.77% |
| crates/accelerate/src/target_transpiler/mod.rs | 8 | 79.0% |
| <!-- | Total: | 25 |
| Totals | |
|---|---|
| Change from base Build 11332886976: | -0.004% |
| Covered Lines: | 73192 |
| Relevant Lines: | 82555 |
💛 - Coveralls
Thank you for checking this @ElePT, I couldn't replicate Jun's specific issue. But I do have an idea of how to replicate it. I will add unit tests soon. Thank you!
Actually the test-case for this has proven a bit harder to compose. This problem appeared to happen on previous versions of our code and only if Qiskit is ran with parallelization during some stage of instruction_supported. I will continue to look into this, the bug has been fixed but it would be great to include a test case for this as well.