forked from lehner/gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
ot
handling in lattice +
composition
Fixes lehner#146 Implement new `ot` handling in lattice `+` composition. * Add addition lookup table to `ot_base` in `lib/gpt/core/object_type/base.py`. * Implement automatic embedding for `complex` to `ot_singlet` lattice in `lib/gpt/core/object_type/base.py`. * Add explicit casting functions for explicit embedding/projection in `lib/gpt/core/object_type/base.py`. * Add unit tests for new `ot` handling in lattice `+` composition in `tests/core/expr.py`.
- Loading branch information
1 parent
5003e00
commit 48b4cd0
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import gpt as g | ||
import numpy as np | ||
|
||
def test_factor_unary(): | ||
grid = g.grid([8, 8, 8, 16], g.double) | ||
v = g.vspincolor(grid) | ||
adj_v = g.adj(v) | ||
result = g(adj_v + v) | ||
assert result.otype.__name__ == "ot_vector_spin_color(4,3)" | ||
|
||
def test_addition_with_complex(): | ||
grid = g.grid([8, 8, 8, 16], g.double) | ||
singlet = g.singlet(grid) | ||
result = g(singlet + 2.0j) | ||
assert result.otype.__name__ == "ot_singlet" | ||
|
||
def test_automatic_embedding(): | ||
grid = g.grid([8, 8, 8, 16], g.double) | ||
singlet = g.singlet(grid) | ||
result = g(singlet + 2.0j) | ||
assert result.otype.__name__ == "ot_singlet" | ||
|
||
def test_explicit_casting(): | ||
grid = g.grid([8, 8, 8, 16], g.double) | ||
singlet = g.singlet(grid) | ||
casted = g.convert(singlet, g.ot_singlet()) | ||
assert casted.otype.__name__ == "ot_singlet" | ||
|
||
if __name__ == "__main__": | ||
test_factor_unary() | ||
test_addition_with_complex() | ||
test_automatic_embedding() | ||
test_explicit_casting() | ||
print("All tests passed.") |