Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

BugFix in adjoint of SynthesizeLRCircuit #1553

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions qualtran/bloqs/gf_arithmetic/gf2_multiplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ def signature(self) -> 'Signature':
return Signature([Register('q', QBit(), shape=(n,))])

def on_classical_vals(self, *, q: 'ClassicalValT') -> Dict[str, 'ClassicalValT']:
matrix = self.matrix
if is_symbolic(self.matrix):
raise ValueError(f"Cannot do classical simulation on symbolic {self}")
matrix = GF(2)(self.matrix.astype(int))
assert isinstance(q, np.ndarray)
q = GF(2)(q)
assert isinstance(matrix, np.ndarray)
if self.is_adjoint:
matrix = np.linalg.inv(matrix)
assert np.allclose(matrix, matrix.astype(int))
matrix = matrix.astype(int)
matrix = GF(2)(np.linalg.inv(matrix))
_, m = matrix.shape
assert isinstance(q, np.ndarray)
return {'q': (matrix @ q) % 2}
return {'q': np.array(matrix @ q)}

def build_call_graph(
self, ssa: 'SympySymbolAllocator'
Expand Down
4 changes: 2 additions & 2 deletions qualtran/bloqs/gf_arithmetic/gf2_multiplication_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def test_gf2_multiplication_symbolic(bloq_autotester):
bloq_autotester(_gf2_multiplication_symbolic)


def test_synthesize_lr_circuit():
m = 2
@pytest.mark.parametrize('m', [2, 4, 6, 8])
def test_synthesize_lr_circuit(m: int):
matrix = GF2Multiplication(m).reduction_matrix_q
bloq = SynthesizeLRCircuit(matrix)
bloq_adj = bloq.adjoint()
Expand Down