Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ShellyGarion
Copy link
Member

Summary

close #14002

Details and comments

@ShellyGarion ShellyGarion added this to the 2.0.0 milestone Mar 17, 2025
@ShellyGarion ShellyGarion requested a review from a team as a code owner March 17, 2025 17:14
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core
  • @levbishop

@coveralls
Copy link

Pull Request Test Coverage Report for Build 13905655333

Details

  • 1 of 4 (25.0%) changed or added relevant lines in 1 file are covered.
  • 11 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.01%) to 88.074%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/two_qubit_decompose.rs 1 4 25.0%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 5 92.48%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 13905217637: -0.01%
Covered Lines: 72593
Relevant Lines: 82423

💛 - 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):
Copy link
Member

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.

Copy link
Member Author

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'

@raynelfss raynelfss self-assigned this Mar 18, 2025
Copy link
Contributor

@raynelfss raynelfss left a 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())
Copy link
Contributor

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.

Comment on lines +2931 to +2933
fn __getnewargs__(&self) -> (RXXEquivalent, &str) {
(self.rxx_equivalent_gate.clone(), self.euler_basis.as_str())
}
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TwoQubitControlledUDecomposer is missing pickle support
5 participants