Skip to content

Commit 8593e2d

Browse files
authored
BugFix in adjoint of SynthesizeLRCircuit (#1553)
* BugFix in adjoint of SynthesizeLRCircuit * Fix mypy and add tests that fail earlier and pass now
1 parent 25d9369 commit 8593e2d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

qualtran/bloqs/gf_arithmetic/gf2_multiplication.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,17 @@ def signature(self) -> 'Signature':
7373
return Signature([Register('q', QBit(), shape=(n,))])
7474

7575
def on_classical_vals(self, *, q: 'ClassicalValT') -> Dict[str, 'ClassicalValT']:
76-
matrix = self.matrix
76+
if is_symbolic(self.matrix):
77+
raise ValueError(f"Cannot do classical simulation on symbolic {self}")
78+
matrix = GF(2)(self.matrix.astype(int))
79+
assert isinstance(q, np.ndarray)
80+
q = GF(2)(q)
7781
assert isinstance(matrix, np.ndarray)
7882
if self.is_adjoint:
79-
matrix = np.linalg.inv(matrix)
80-
assert np.allclose(matrix, matrix.astype(int))
81-
matrix = matrix.astype(int)
83+
matrix = GF(2)(np.linalg.inv(matrix))
8284
_, m = matrix.shape
8385
assert isinstance(q, np.ndarray)
84-
return {'q': (matrix @ q) % 2}
86+
return {'q': np.array(matrix @ q)}
8587

8688
def build_call_graph(
8789
self, ssa: 'SympySymbolAllocator'

qualtran/bloqs/gf_arithmetic/gf2_multiplication_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def test_gf2_multiplication_symbolic(bloq_autotester):
4242
bloq_autotester(_gf2_multiplication_symbolic)
4343

4444

45-
def test_synthesize_lr_circuit():
46-
m = 2
45+
@pytest.mark.parametrize('m', [2, 4, 6, 8])
46+
def test_synthesize_lr_circuit(m: int):
4747
matrix = GF2Multiplication(m).reduction_matrix_q
4848
bloq = SynthesizeLRCircuit(matrix)
4949
bloq_adj = bloq.adjoint()

0 commit comments

Comments
 (0)