refactor: make scalar-handling backend agnostic#339
Open
akissinger wants to merge 2 commits intomasterfrom
Open
refactor: make scalar-handling backend agnostic#339akissinger wants to merge 2 commits intomasterfrom
akissinger wants to merge 2 commits intomasterfrom
Conversation
Member
Author
|
@lara-madison and @jvdwetering can I go ahead and merge this? Hopefully it doesn't clobber anything else you are working on at the moment. |
Collaborator
|
That seems reasonable to me. I also agree that these names make more sense. We could also change the names of the corresponding method of the Scalar class, but that doesn't have to be in this PR. |
Contributor
|
@akissinger @jvdwetering If there's no further work necessary for this PR, can you please merge it before it diverges too much from the main branch? |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently the way PyZX handles scalars is not compatible with the Rust backend. The reason for this is Rust stores its scalars differently, so asking for the scalar from the python bindings returns a (lossy) copy of the current scalar. Hence, code like this which mutates the scalar doesn't work as expected:
I suggest we deprecate mutating the scalar directly, and do this all via helper methods added to
BaseGraph, which are added by this PR:This lets the Rust backend override these methods to do the correct thing.
I will probably go ahead and merge this soon and also change all of the instances I find of mutating the scalar, since this shouldn't break anything. However, on the long term, we might want to look at e.g. renaming
Basegraph.scalartoBasegraph._scalarto enforce using the helpers.