Add in-place variants for infer_pauli_measurements, to_bloch,... - #568
Conversation
Method `Pattern.infer_pauli_measurements` now operates in place by default, with an optional `copy` parameter. If `copy=True`, a modified copy is returned instead. Added the following methods to `Pattern`. By default, they modify the pattern in place, with an optional `copy` parameter. If `copy=True`, a modified copy is returned instead. - `apply`, an in-place variant of `map`, - `blochify`, an in-place variant of `to_bloch`, - `substitute`, an in-place variant of `subs`, - `replace_parameters`, an in-place variant of `xreplace`. This is a step toward the cleaner simulation API proposed in TeamGraphix#493. It also makes the examples in the Graphix paper cleaner.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #568 +/- ##
==========================================
+ Coverage 89.11% 89.26% +0.15%
==========================================
Files 49 49
Lines 7716 7791 +75
==========================================
+ Hits 6876 6955 +79
+ Misses 840 836 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
matulni
left a comment
There was a problem hiding this comment.
Thanks for the change, new functions are useful!
I'm not convinced by the naming of the parametric angle functions. The following are not very intuitive to me:
subsandsubstitutehave the same relationship asxreplaceandreplace_parameters.substituteandreplace_parametersact in-place.subsreplaces one parameter, andxreplacereplaces multiple parameters in parallel. (I'm aware that this is a sympy convention and that it's independent of this PR, but I always found it difficult to remember. In addition, with the new methods we drift away from sympy's convention).
Here are two alternatives:
A)
substitute -> subs_in_place
replace_parameters -> xreplace_in_place
It solves 1) and 2), but it's more verbose and not true when calling subs_in_place(..., copy=True).
B)
subs -> substituted
substitute remains
xreplace -> substituted_multi
replace_parameters -> substitute_multi
I think this solves all three points but we don't follow sympy convention at all, and it requires a larger refactoring (we would need to update analogous methods in OpenGraph, etc.). If you think the -ed suffix may be easier to miss when reading the code, we could use with_substitution instead.
What do you think ?
pranav97nair
left a comment
There was a problem hiding this comment.
Thanks for this change. The new functions look good to me.
|
Thank you, @matulni and @pranav97nair, for your reviews. I consolidate the API changes:
Moreover, I added a class |
matulni
left a comment
There was a problem hiding this comment.
Thanks a lot for implementing this changes, it's a lot of work.
I'm happy with all the changes regarding the parametric substitution.
However, I believe that the new shared methods in the AbstractStatevector class won't work with the symbolic backend (I give a specific example below). I suspect that the code is not generic enough to work on the GPU backend either.
Making this methods work requires some additional work on the symbolic backend, which I don't think is worth at all. Then, as it is now, I don't think we need the AbstractStatevector class. I agree that in the future it could be practical if we implement others backend more useful than the symbolic one, but can see then.
Something I missed: is the AbstractStatevector class necessary to make the new work on the parametric substitution work ? Couldn't we leave it for a future PR ?
Co-authored-by: matulni <m.uldemolins@gmail.com>
Co-authored-by: matulni <m.uldemolins@gmail.com>
Co-authored-by: matulni <m.uldemolins@gmail.com>
Co-authored-by: matulni <m.uldemolins@gmail.com>
Co-authored-by: matulni <m.uldemolins@gmail.com>
Co-authored-by: matulni <m.uldemolins@gmail.com>
Co-authored-by: Pranav Nair <61292693+pranav97nair@users.noreply.github.com>
Co-authored-by: Pranav Nair <61292693+pranav97nair@users.noreply.github.com>
Method
Pattern.infer_pauli_measurementsnow operates in place by default, with an optionalcopyparameter. Ifcopy=True, a modified copy is returned instead.Added the following methods to
Pattern. By default, they modify the pattern in place, with an optionalcopyparameter. Ifcopy=True, a modified copy is returned instead.apply, an in-place variant ofmap,blochify, an in-place variant ofto_bloch,substitute, an in-place variant ofsubs,replace_parameters, an in-place variant ofxreplace.This is a step toward the cleaner simulation API proposed in #493. It also makes the examples in the Graphix paper cleaner.