-
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
Add pickle support of TwoQubitControlledUDecomposer #14038
base: main
Are you sure you want to change the base?
Conversation
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 13905655333Details
💛 - Coveralls |
@@ -149,6 +149,16 @@ def assertDebugOnly(self): # FIXME: when at python 3.10+ replace with assertNoL | |||
) | |||
self.assertIn("Requested fidelity:", record.getMessage()) | |||
|
|||
def assertPickle(self, decomp: TwoQubitControlledUDecomposer): |
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.
There isn't a test using this method so this code is never executed. If you want to use this method you'll have to add a test that calls it. Something prefixed with test_
will do that.
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 updated the test, and now it's failing.
with a standard gate it fails with: TypeError: cannot pickle 'qiskit._accelerate.circuit.StandardGate' object
with a customized gate it fails with: AttributeError: Can't pickle local object 'TestTwoQubitControlledUDecompose.test_assertPickle.<locals>.CustomXXGate'
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.
Thank you for workign on this Shelly, I believe you are very close to the solution. I have a couple of suggestions that might help.
@@ -2928,6 +2928,9 @@ impl TwoQubitControlledUDecomposer { | |||
/// for 1Q synthesis. | |||
/// Raises: | |||
/// QiskitError: If the gate is not locally equivalent to an :class:`.RXXGate`. | |||
fn __getnewargs__(&self) -> (RXXEquivalent, &str) { | |||
(self.rxx_equivalent_gate.clone(), self.euler_basis.as_str()) |
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 believe that rust StandardGate
instances are not pickle-able. I'm not sure if this is by design but, assuming it is, you should use the get_std_gate_class
method here when returning to Python (For this you might wanna implement IntoPyObject
for RXXEquivalent
manually instead of using a derive-macro). Since the python counterpart is pickleable, this should make for an easier transition.
fn __getnewargs__(&self) -> (RXXEquivalent, &str) { | ||
(self.rxx_equivalent_gate.clone(), self.euler_basis.as_str()) | ||
} |
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.
You might want to move this method out of the way, since it is interfering with the docstring that's meant for new
.
Summary
close #14002
Details and comments