Add in-place variants for infer_pauli_measurements, to_bloch,...#568
Add in-place variants for infer_pauli_measurements, to_bloch,...#568thierry-martinez wants to merge 3 commits into
infer_pauli_measurements, to_bloch,...#568Conversation
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 90.58% 90.59% +0.01%
==========================================
Files 49 49
Lines 7481 7489 +8
==========================================
+ Hits 6777 6785 +8
Misses 704 704 ☔ 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 ?
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.