-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Remove the commutation cache from the commutation checker #15988
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| from qiskit.circuit.operation import Operation | ||
| from qiskit.circuit import Qubit | ||
| from qiskit._accelerate.commutation_checker import CommutationChecker as RustChecker | ||
| from qiskit.utils import deprecate_arg, deprecate_func | ||
|
|
||
|
|
||
| class CommutationChecker: | ||
|
|
@@ -45,18 +46,18 @@ class CommutationChecker: | |
| gates with free parameters (such as :class:`.RXGate` with a :class:`.ParameterExpression` as | ||
| angle). Otherwise, a matrix-based check is performed, where two operations are said to | ||
| commute, if the average gate fidelity of performing the commutation is above a certain threshold | ||
| (see ``approximation_degree``). The result of this commutation is then added to the | ||
| cached lookup table. | ||
| (see ``approximation_degree``). | ||
| """ | ||
|
|
||
| @deprecate_arg("cache_max_entries", since="2.5.0", removal_timeline="in Qiskit 3.0") | ||
| def __init__( | ||
| self, | ||
| standard_gate_commutations: dict | None = None, | ||
| cache_max_entries: int = 10**6, | ||
| *, | ||
| gates: set[str] | None = None, | ||
| ): | ||
| self.cc = RustChecker(standard_gate_commutations, cache_max_entries, gates) | ||
| self.cc = RustChecker(standard_gate_commutations, gates) | ||
|
|
||
| def commute_nodes( | ||
| self, | ||
|
|
@@ -118,13 +119,21 @@ def commute( | |
| matrix_max_num_qubits, | ||
| ) | ||
|
|
||
| @deprecate_func(since="2.5", removal_timeline="in Qiskit 3.0") | ||
| def num_cached_entries(self): | ||
| """Returns number of cached entries""" | ||
| return self.cc.num_cached_entries() | ||
| """Returns number of cached entries | ||
|
|
||
| This method will always return 0 because there is no longer an | ||
| internal cache. | ||
| """ | ||
| return 0 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this is a backward compatible API change, since the commutation checker does give the same results, just might take longer, but we are dropping functionality user's might've relied upon. I think it would be nice to point this out more explicitly in the release notes, what do you think?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can reword the release note to make it more explicit. Do you want me to add an Functionally the caching only did anything in a very specific case, you had a gate pair of
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rewording is good enough, just to point out users would have to do their own caching if they relied on that 👍🏻 I also don't think it's a commonly used thing, but the past has shown that every minuscule feature is used somehow by someone 😄 |
||
|
|
||
| @deprecate_func(since="2.5", removal_timeline="in Qiskit 3.0") | ||
| def clear_cached_commutations(self): | ||
| """Clears the dictionary holding cached commutations""" | ||
| self.cc.clear_cached_commutations() | ||
| """Clears the dictionary holding cached commutations | ||
|
|
||
| This method is a no-op as there is no longer an internal cache | ||
| """ | ||
|
|
||
| def check_commutation_entries( | ||
| self, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| deprecations_circuits: | ||
| - The ``cache_max_entries`` argument on the the :class:`.CommutationChecker` class's | ||
| constructor is deprecated and will be removed in Qiskit 3.0.0. This argument no longer has | ||
| any effect because the :class:`.CommutationChecker` no longer maintains an internal cache | ||
| of commutation relationships between gates as it is no longer necessary. | ||
| - The :meth:`.CommutationChecker.clear_cached_commutations` method is deprecated and will be | ||
| removed in Qiskit 3.0.0. This method no longer has any effect because the | ||
| internal cache was removed from the :class:`.CommutationChecker` class as | ||
| it was no longer necessary so there is nothing to clear. | ||
| - The :meth:`.CommutationChecker.num_cached_entries` method is deprecated | ||
| and will be removed in Qiskit 3.0.0. Since the removal of the internal | ||
| cache from the :class:`.CommutationChecker` this method always returns 0 | ||
| because there are no internally cached entries in a :class:`.CommutationChecker` | ||
| instance. |
Uh oh!
There was an error while loading. Please reload this page.