-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Do not raise deprecation warnings for internal uses of dag.duration and dag.unit #14133
Conversation
…ternally Filter Rust deprecation warning when calling dag.duration/dag.unit internally
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 14173060988Warning: 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
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of filtering warnings which is kind of imprecise shouldn't we just adjust the access patterns to not trigger a warning? It's pretty simple in this case by just adding and using _duration
and _unit
qiskit/converters/dag_to_circuit.py
Outdated
@@ -75,6 +76,19 @@ def dag_to_circuit(dag, copy_operations=True): | |||
circuit.metadata = dag.metadata or {} | |||
circuit._data = circuit_data | |||
|
|||
circuit._duration = dag.duration | |||
circuit._unit = dag.unit | |||
with warnings.catch_warnings(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of filtering the warning why not just use the internal attribute which doesn't have the warning?
We explicitly set the stack level to because we're just calling
If the filter is masking bugs we should remove it. |
It doesn't because the Rust-space call is invisible to Python: qiskit/crates/circuit/src/circuit_instruction.rs Lines 687 to 711 in 82b2da2
|
Ah, then the fix here is simply changing the |
* Refactor access patterns: add dag._duration and dag._unit * Refactor internal uses of dag.duration and dag.unit to rely on internal methods * Remove blanket warning filters from unit test config On top of these: * Extend deprecation warnings to dag.duration and dag.unit setters (previously only in getters) * Clean up unit test config from old filters
Heh, saw the last suggestion too late. But it's probably good not to have internal calls to deprecated methods anyways, and I also added a deprecation warning on the setter that I think we were missing (correct me if I'm wrong). |
Oh yeah, I'm not a fan of using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM now thanks for updating this.
crates/circuit/src/dag_circuit.rs
Outdated
@@ -521,12 +519,49 @@ impl DAGCircuit { | |||
) | |||
), | |||
py.get_type::<PyDeprecationWarning>(), | |||
2, | |||
1, | |||
))?; | |||
Ok(self.duration.as_ref().map(|x| x.clone_ref(py))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably could have done this to deduplicate the code a little bit:
Ok(self.duration.as_ref().map(|x| x.clone_ref(py))) | |
self.get_internal_duration(py) |
but it's not a big deal. Not worth blocking over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to change a small detail to fix lint so I can also fix this
…nd dag.unit (#14133) * Filter Rust deprecation warning when calling dag.duration/dag.unit internally Filter Rust deprecation warning when calling dag.duration/dag.unit internally * Apply Matt's suggestions: * Refactor access patterns: add dag._duration and dag._unit * Refactor internal uses of dag.duration and dag.unit to rely on internal methods * Remove blanket warning filters from unit test config On top of these: * Extend deprecation warnings to dag.duration and dag.unit setters (previously only in getters) * Clean up unit test config from old filters * Change stacklevel * Fix circuit_to_dag * Handle failing tests * _DAGDependencyV2 is private and not a DAGCircuit, so don't use internal attributes * Reduce duplication in getters and setters (cherry picked from commit d0aa100)
…nd dag.unit (#14133) (#14140) * Filter Rust deprecation warning when calling dag.duration/dag.unit internally Filter Rust deprecation warning when calling dag.duration/dag.unit internally * Apply Matt's suggestions: * Refactor access patterns: add dag._duration and dag._unit * Refactor internal uses of dag.duration and dag.unit to rely on internal methods * Remove blanket warning filters from unit test config On top of these: * Extend deprecation warnings to dag.duration and dag.unit setters (previously only in getters) * Clean up unit test config from old filters * Change stacklevel * Fix circuit_to_dag * Handle failing tests * _DAGDependencyV2 is private and not a DAGCircuit, so don't use internal attributes * Reduce duplication in getters and setters (cherry picked from commit d0aa100) Co-authored-by: Elena Peña Tapia <[email protected]>
@Mergifyio backport stable/1.4 |
✅ Backports have been created
|
…nd dag.unit (#14133) * Filter Rust deprecation warning when calling dag.duration/dag.unit internally Filter Rust deprecation warning when calling dag.duration/dag.unit internally * Apply Matt's suggestions: * Refactor access patterns: add dag._duration and dag._unit * Refactor internal uses of dag.duration and dag.unit to rely on internal methods * Remove blanket warning filters from unit test config On top of these: * Extend deprecation warnings to dag.duration and dag.unit setters (previously only in getters) * Clean up unit test config from old filters * Change stacklevel * Fix circuit_to_dag * Handle failing tests * _DAGDependencyV2 is private and not a DAGCircuit, so don't use internal attributes * Reduce duplication in getters and setters (cherry picked from commit d0aa100) # Conflicts: # crates/circuit/src/dag_circuit.rs # qiskit/transpiler/passes/scheduling/padding/base_padding.py # test/python/circuit/test_scheduled_circuit.py # test/python/compiler/test_transpiler.py # test/utils/base.py
…nd dag.unit (backport #14133) (#14147) * Do not raise deprecation warnings for internal uses of dag.duration and dag.unit (#14133) * Filter Rust deprecation warning when calling dag.duration/dag.unit internally Filter Rust deprecation warning when calling dag.duration/dag.unit internally * Apply Matt's suggestions: * Refactor access patterns: add dag._duration and dag._unit * Refactor internal uses of dag.duration and dag.unit to rely on internal methods * Remove blanket warning filters from unit test config On top of these: * Extend deprecation warnings to dag.duration and dag.unit setters (previously only in getters) * Clean up unit test config from old filters * Change stacklevel * Fix circuit_to_dag * Handle failing tests * _DAGDependencyV2 is private and not a DAGCircuit, so don't use internal attributes * Reduce duplication in getters and setters (cherry picked from commit d0aa100) # Conflicts: # crates/circuit/src/dag_circuit.rs # qiskit/transpiler/passes/scheduling/padding/base_padding.py # test/python/circuit/test_scheduled_circuit.py # test/python/compiler/test_transpiler.py # test/utils/base.py * Fix merge conflicts * Address failing tests * More fixes * More fixes * Last try --------- Co-authored-by: Elena Peña Tapia <[email protected]> Co-authored-by: Elena Peña Tapia <[email protected]>
Summary
dag.duration
anddag.unit
raise a deprecation warning from Rust which I believe doesn't follow the right stack level, because every timedag_to_circuit
is called, these deprecation warnings are raised to the user as if they were user-actionable (which they are not). This happens not only for direct calls todag_to_circuit
(and a couple others), but also every timedag_to_circuit
is used internally, flooding test runs and confusing both users and downstream package devs.We don't see them because we have a blanket filter in our unit test configuration, but now that the deprecation warnings are going to stay until 3.0, I think that at least a filter would improve the user experience of
dag_to_circuit
.Details and comments