Refactor Arithmetic Operations on AmplitudeVector - #234
Open
jonasleitner wants to merge 5 commits into
Open
Conversation
| @overload | ||
| def dot( | ||
| self, other: Sequence["AmplitudeVector"] | ||
| ) -> np.ndarray[tuple[int], np.dtype[np.float64]]: |
Contributor
There was a problem hiding this comment.
We would currently mix plain np.ndarray and parameterized np.ndarray[...]. I would prefer the parameterized form where possible. For example, ElectronicTransition.py uses the unparameterized form.
What do you think @jonasleitner ?
Contributor
Author
There was a problem hiding this comment.
I also prefer the parametrized form including shape and optionally the data type. However, I would suggest to resolve this at a later stage once we revisit the corresponding files regarding type hints?
Co-authored-by: Friederike Schneider <110526409+frieschneider@users.noreply.github.com>
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.
This PR refactors the arithmetic operations implemented on the
AmplitudeVectorclass such that missing blocks are consistently treated as zero blocks.Previously, this was only the case for
__add__, while the other operations employed__forward_to_blocks, which raised an exception for differing blocks. Moreover,dotshowed inconsistent behavior,ADC1.dot(ADC2)gave thephoverlap, whileADC2.dot(ADC1)raised an exception due to a missingpphhblock. The in-place operators, also employed__forward_to_blocks, which created a newAmplitudeVectorinstance and thus were not really in-place.In this PR I explicitly implemented the arithmetic operations ensuring that inputs and result don't share memory (
libadcc.Tensorsare copied if necessary). Moreover, in-place operations mutate the current instance modifying/deleting existing blocks.Finally, type hints are introduced throughout
AmplitudeVector.pyA Note on the reflective operations:
libadcc.Tensor * Amplitude(same for other operations) is not possible, since the backend raises aTypeError. Thus,__rmul__etc. are not reachable for this case and the implementation contains in principle dead code.