-
Notifications
You must be signed in to change notification settings - Fork 0
Add fermion arrow. #17
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,11 +19,19 @@ class ParityTensor: | |||||
| Each dimension of the tensor is composed of an even and an odd part, represented as a pair of integers. | ||||||
| """ | ||||||
|
|
||||||
| _arrow: tuple[bool, ...] | ||||||
| _edges: tuple[tuple[int, int], ...] | ||||||
| _tensor: torch.Tensor | ||||||
| _parity: tuple[torch.Tensor, ...] | None = None | ||||||
| _mask: torch.Tensor | None = None | ||||||
|
|
||||||
| @property | ||||||
| def arrow(self) -> tuple[bool, ...]: | ||||||
| """ | ||||||
| The arrow of the tensor, represented as a tuple of booleans indicating the order of the fermion operators. | ||||||
| """ | ||||||
| return self._arrow | ||||||
|
|
||||||
| @property | ||||||
| def edges(self) -> tuple[tuple[int, int], ...]: | ||||||
| """ | ||||||
|
|
@@ -80,6 +88,7 @@ def permute(self, before_by_after: tuple[int, ...]) -> ParityTensor: | |||||
| """ | ||||||
| assert set(before_by_after) == set(range(self.tensor.dim())), "Permutation indices must cover all dimensions." | ||||||
|
|
||||||
| arrow = tuple(self.arrow[i] for i in before_by_after) | ||||||
| edges = tuple(self.edges[i] for i in before_by_after) | ||||||
| tensor = self.tensor.permute(before_by_after) | ||||||
| parity = tuple(self.parity[i] for i in before_by_after) | ||||||
|
|
@@ -98,13 +107,15 @@ def permute(self, before_by_after: tuple[int, ...]) -> ParityTensor: | |||||
|
|
||||||
| return dataclasses.replace( | ||||||
| self, | ||||||
| _arrow=arrow, | ||||||
| _edges=edges, | ||||||
| _tensor=tensor, | ||||||
| _parity=parity, | ||||||
| _mask=mask, | ||||||
| ) | ||||||
|
|
||||||
| def __post_init__(self) -> None: | ||||||
| assert len(self._arrow) == self._tensor.dim(), f"Arrow length ({len(self._arrow)}) must match tensor dimensions ({self._tensor.dim()})." | ||||||
| assert len(self._edges) == self._tensor.dim(), f"Edges length ({len(self._edges)}) must match tensor dimensions ({self._tensor.dim()})." | ||||||
| for dim, (even, odd) in zip(self._tensor.shape, self._edges): | ||||||
| assert even >= 0 and odd >= 0 and dim == even + odd, f"Dimension {dim} must equal sum of even ({even}) and odd ({odd}) parts, and both must be non-negative." | ||||||
|
|
@@ -126,6 +137,7 @@ def _validate_edge_compatibility(self, other: ParityTensor) -> None: | |||||
| """ | ||||||
| Validate that the edges of two ParityTensor instances are compatible for arithmetic operations. | ||||||
| """ | ||||||
| assert self._arrow == other.arrow, f"Arrows must match for arithmetic operations. Got {self._arrow} and {other.arrow}." | ||||||
|
||||||
| assert self._arrow == other.arrow, f"Arrows must match for arithmetic operations. Got {self._arrow} and {other.arrow}." | |
| assert self.arrow == other.arrow, f"Arrows must match for arithmetic operations. Got {self.arrow} and {other.arrow}." |
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.
The _arrow attribute is declared without a default value, but other attributes like _parity and _mask have default values of None. This inconsistency could cause initialization issues if arrow is not provided during object creation.