-
Notifications
You must be signed in to change notification settings - Fork 334
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
Bug/607 fidelity statevector kernel cannot be pickled #778
Bug/607 fidelity statevector kernel cannot be pickled #778
Conversation
Added a new param to store cache size and a custom __getstate__ and __setstate__ to handle removing and re-initliasing the lru cache during pickle/unpickling respectively.
…orKernel-cannot-be-pickled
https://github.com/OkuyanBoga/hc-qiskit-machine-learning into bug/607---FidelityStatevectorKernel-cannot-be-pickled
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.
Normally if we have a bug that does not show up in the test cases it suggests we need one to test that aspects for better coverage and to make sure it things stay working. I think a test case that pickles and unpickles is needed.
releasenotes/notes/fix-fid_statevector_kernel-pickling-b7fa2b13a15ec9c6.yaml
Outdated
Show resolved
Hide resolved
Does that mean a test is needed where we pickle and unpickle all qml objects? |
Seems like a lot of objects! This is much more an edge case I guess due to lru_cache so I would leave it at just a test for this object - makes sure it works in CI over the platforms and continues to do so. |
Pull Request Test Coverage Report for Build 8098671846Details
💛 - Coveralls |
Added unit testing and edited release notes. |
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.
Thanks very much for addressing this issue! I just have a few minor suggestions.
releasenotes/notes/fix-fid_statevector_kernel-pickling-b7fa2b13a15ec9c6.yaml
Outdated
Show resolved
Hide resolved
…3a15ec9c6.yaml Co-authored-by: Declan Millar <[email protected]>
Co-authored-by: Declan Millar <[email protected]>
Co-authored-by: Declan Millar <[email protected]>
Co-authored-by: Declan Millar <[email protected]>
Co-authored-by: Declan Millar <[email protected]>
Co-authored-by: Declan Millar <[email protected]>
I appreciate the suggestions! I'm surprised some of them weren't picked up by CI. All the changes were approved. |
You'll need to add |
Can do, why does it need to be added? - for the dict, got it |
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.
Looks good to me. Thank you.
* Made fidelity_statevector_kernel picklable Added a new param to store cache size and a custom __getstate__ and __setstate__ to handle removing and re-initliasing the lru cache during pickle/unpickling respectively. * updated notes * name changes * spell corrections * Updated description * Added unittest for pickling * Spelling changes * Making error messages clearer * Spelling -_- * Update releasenotes/notes/fix-fid_statevector_kernel-pickling-b7fa2b13a15ec9c6.yaml Co-authored-by: Declan Millar <[email protected]> * Update .gitignore Co-authored-by: Declan Millar <[email protected]> * Update test/kernels/test_fidelity_statevector_kernel.py Co-authored-by: Declan Millar <[email protected]> * Update qiskit_machine_learning/kernels/fidelity_statevector_kernel.py Co-authored-by: Declan Millar <[email protected]> * Update test/kernels/test_fidelity_statevector_kernel.py Co-authored-by: Declan Millar <[email protected]> * Update qiskit_machine_learning/kernels/fidelity_statevector_kernel.py Co-authored-by: Declan Millar <[email protected]> * Added Any class --------- Co-authored-by: M. Emre Sahin <[email protected]> Co-authored-by: Declan Millar <[email protected]> Co-authored-by: Anton Dekusar <[email protected]> (cherry picked from commit c59063a)
* Made fidelity_statevector_kernel picklable Added a new param to store cache size and a custom __getstate__ and __setstate__ to handle removing and re-initliasing the lru cache during pickle/unpickling respectively. * updated notes * name changes * spell corrections * Updated description * Added unittest for pickling * Spelling changes * Making error messages clearer * Spelling -_- * Update releasenotes/notes/fix-fid_statevector_kernel-pickling-b7fa2b13a15ec9c6.yaml Co-authored-by: Declan Millar <[email protected]> * Update .gitignore Co-authored-by: Declan Millar <[email protected]> * Update test/kernels/test_fidelity_statevector_kernel.py Co-authored-by: Declan Millar <[email protected]> * Update qiskit_machine_learning/kernels/fidelity_statevector_kernel.py Co-authored-by: Declan Millar <[email protected]> * Update test/kernels/test_fidelity_statevector_kernel.py Co-authored-by: Declan Millar <[email protected]> * Update qiskit_machine_learning/kernels/fidelity_statevector_kernel.py Co-authored-by: Declan Millar <[email protected]> * Added Any class --------- Co-authored-by: M. Emre Sahin <[email protected]> Co-authored-by: Declan Millar <[email protected]> Co-authored-by: Anton Dekusar <[email protected]> (cherry picked from commit c59063a) Co-authored-by: oscar-wallis <[email protected]>
Summary
Fixes #607 where FidelityStatevectorKernel was throwing an error when pickled due to a known pickling error with functools.lru_cache. This has been fixed by adding a self.cache_size attribute and custom getstate and setstate functions used when pickling and unpickling.
Details and comments
When pickled the lru_cache is set to None in the object dict. When unpicked the cache is re-initiliased with the new cache_size variable and getstate and setstate. Unit tests added to check object pickling and unpickling as well as manually using getstate and setstate to initialise a FidelityStatevectorKernel. Passed all other unit tests.