Skip to content

Commit 5627b53

Browse files
committed
Add unit tests for Multitensor dual basis arg
1 parent 1a49ff0 commit 5627b53

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/openfermion/contrib/representability/_multitensor_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,33 @@ def test_add_dualelement():
9494
mt.add_dual_elements(dbe)
9595
assert len(mt.dual_basis) == 1
9696

97+
dbe2 = DualBasisElement()
98+
dbe2.add_element('b', (0, 1, 2), 5)
99+
mt.add_dual_elements(dbe2)
100+
assert len(mt.dual_basis) == 2
101+
102+
A, bias, scalar = mt.synthesize_dual_basis()
103+
assert A.shape[0] == 2
104+
# Verify that the elements are correctly added as DualBasisElements
105+
# and not as their internal tuples (which would cause synthesis to fail).
106+
assert isinstance(mt.dual_basis[0], DualBasisElement)
107+
assert isinstance(mt.dual_basis[1], DualBasisElement)
108+
109+
110+
def test_multitensor_init_isolation():
111+
# Test that different MultiTensor instances don't share the same dual_basis.
112+
a = np.random.random((2, 2))
113+
at = Tensor(tensor=a, name='a')
114+
mt1 = MultiTensor([at])
115+
mt2 = MultiTensor([at])
116+
117+
dbe = DualBasisElement()
118+
dbe.add_element('a', (0, 0), 1.0)
119+
mt1.add_dual_elements(dbe)
120+
121+
assert len(mt1.dual_basis) == 1
122+
assert len(mt2.dual_basis) == 0
123+
97124

98125
def test_synthesis_element():
99126
a = np.random.random((5, 5))

0 commit comments

Comments
 (0)