-
Notifications
You must be signed in to change notification settings - Fork 65
Add in-place variants for infer_pauli_measurements, to_bloch,...
#568
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
Open
thierry-martinez
wants to merge
15
commits into
TeamGraphix:master
Choose a base branch
from
thierry-martinez:in-place_methods
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4c0e001
Add in-place variants for `infer_pauli_measurements`, `to_bloch`,...
thierry-martinez ef37b2e
Fix docstrings of `xreplace` and `replace_parameters`
thierry-martinez 86f69ce
Fix docstrings for `subs`
thierry-martinez 7432c1c
Uniformize `replace_parameter(s)` and `with_parameter(s)`
thierry-martinez b72eced
Merge branch 'master' into in-place_methods
thierry-martinez 0a4de18
Add `AbstractStatevector` for pretty-printing symbolic statevectors
thierry-martinez 294ff58
Fixes for pyright
thierry-martinez e1d5790
More general flatten
thierry-martinez 36800f0
Move `Self` in `TYPE_CHECKING`
thierry-martinez be2b0ce
Change repo for graphix-symbolic
thierry-martinez 9c39dec
Fix coverage
thierry-martinez ac190c0
Fix coverage again
thierry-martinez 461eed7
Fix typo
thierry-martinez e847870
Merge branch 'master' into in-place_methods
thierry-martinez ccb1858
Fix docstring
thierry-martinez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |||||
| ) | ||||||
| from graphix.fundamentals import AbstractMeasurement, AbstractPlanarMeasurement, Axis, Plane | ||||||
| from graphix.measurements import Measurement | ||||||
| from graphix.parameter import Parameterizable | ||||||
| from graphix.pretty_print import OutputFormat, flow_to_str, xzcorr_to_str | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
|
|
@@ -74,7 +75,7 @@ | |||||
|
|
||||||
|
|
||||||
| @dataclass(frozen=True) | ||||||
| class XZCorrections(Generic[_AM_co]): | ||||||
| class XZCorrections(Parameterizable, Generic[_AM_co]): | ||||||
| """An unmutable dataclass providing a representation of XZ-corrections. | ||||||
|
|
||||||
| Attributes | ||||||
|
|
@@ -518,7 +519,10 @@ def draw(self, **options: Unpack[DrawKwargs]) -> None: | |||||
| gv = GraphVisualizer.from_xzcorrections(xz_corr=self, **options) | ||||||
| gv.visualize() | ||||||
|
|
||||||
| def subs(self: XZCorrections[_M], variable: Parameter, substitute: ExpressionOrSupportsFloat) -> XZCorrections[_M]: | ||||||
| @override | ||||||
| def with_parameter( | ||||||
| self: XZCorrections[_M], variable: Parameter, substitute: ExpressionOrSupportsFloat | ||||||
| ) -> XZCorrections[_M]: | ||||||
| """Substitute a parameter with a value or expression in all measurement angles of the open graph. | ||||||
|
|
||||||
| Parameters | ||||||
|
|
@@ -537,10 +541,11 @@ def subs(self: XZCorrections[_M], variable: Parameter, substitute: ExpressionOrS | |||||
| ----- | ||||||
| See notes and examples in :func:`OpenGraph.subs`. | ||||||
| """ | ||||||
| new_og = self.og.subs(variable, substitute) | ||||||
| new_og = self.og.with_parameter(variable, substitute) | ||||||
| return dataclasses.replace(self, og=new_og) | ||||||
|
|
||||||
| def xreplace( | ||||||
| @override | ||||||
| def with_parameters( | ||||||
| self: XZCorrections[_M], assignment: Mapping[Parameter, ExpressionOrSupportsFloat] | ||||||
| ) -> XZCorrections[_M]: | ||||||
| """Perform parallel substitution of multiple parameters in measurement angles of the open graph. | ||||||
|
|
@@ -559,12 +564,12 @@ def xreplace( | |||||
| ----- | ||||||
| See notes and examples in :func:`OpenGraph.xreplace`. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| """ | ||||||
| new_og = self.og.xreplace(assignment) | ||||||
| new_og = self.og.with_parameters(assignment) | ||||||
| return dataclasses.replace(self, og=new_og) | ||||||
|
|
||||||
|
|
||||||
| @dataclass(frozen=True) | ||||||
| class PauliFlow(Generic[_AM_co]): | ||||||
| class PauliFlow(Parameterizable, Generic[_AM_co]): | ||||||
| """An unmutable dataclass providing a representation of a Pauli flow. | ||||||
|
|
||||||
| Attributes | ||||||
|
|
@@ -858,7 +863,8 @@ def draw(self, **options: Unpack[DrawKwargs]) -> None: | |||||
| gv = GraphVisualizer.from_flow(flow=self, **options) | ||||||
| gv.visualize() | ||||||
|
|
||||||
| def subs( # noqa: PYI019 Annotating with ``Self`` is not possible since ``self`` must be of parametric type ``Measurement``. | ||||||
| @override | ||||||
| def with_parameter( # noqa: PYI019 Annotating with ``Self`` is not possible since ``self`` must be of parametric type ``Measurement``. | ||||||
| self: _T_PauliFlowMeasurement, variable: Parameter, substitute: ExpressionOrSupportsFloat | ||||||
| ) -> _T_PauliFlowMeasurement: | ||||||
| """Substitute a parameter with a value or expression in all measurement angles of the open graph. | ||||||
|
|
@@ -879,10 +885,11 @@ def subs( # noqa: PYI019 Annotating with ``Self`` is not possible since ``self` | |||||
| ----- | ||||||
| See notes and examples in :func:`OpenGraph.subs`. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| """ | ||||||
| new_og = self.og.subs(variable, substitute) | ||||||
| new_og = self.og.with_parameter(variable, substitute) | ||||||
| return dataclasses.replace(self, og=new_og) | ||||||
|
|
||||||
| def xreplace( # noqa: PYI019 | ||||||
| @override | ||||||
| def with_parameters( # noqa: PYI019 | ||||||
| self: _T_PauliFlowMeasurement, assignment: Mapping[Parameter, ExpressionOrSupportsFloat] | ||||||
| ) -> _T_PauliFlowMeasurement: | ||||||
| """Perform parallel substitution of multiple parameters in measurement angles of the open graph. | ||||||
|
|
@@ -901,7 +908,7 @@ def xreplace( # noqa: PYI019 | |||||
| ----- | ||||||
| See notes and examples in :func:`OpenGraph.xreplace`. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| """ | ||||||
| new_og = self.og.xreplace(assignment) | ||||||
| new_og = self.og.with_parameters(assignment) | ||||||
| return dataclasses.replace(self, og=new_og) | ||||||
|
|
||||||
| def is_focused(self) -> bool: | ||||||
|
|
||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.