Skip to content

Commit baad879

Browse files
Override KaliskiModInverse.adjoint (#1483)
1 parent bc155b6 commit baad879

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

qualtran/bloqs/mod_arithmetic/mod_division.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import numpy as np
1919
import sympy
20-
from attrs import frozen
20+
from attrs import evolve, frozen
2121

2222
from qualtran import (
2323
Bloq,
@@ -632,6 +632,9 @@ def build_composite_bloq(
632632
bb.free(f)
633633
return {'x': x, 'm': m}
634634

635+
def adjoint(self) -> 'KaliskiModInverse':
636+
return evolve(self, uncompute=not self.uncompute)
637+
635638
def build_call_graph(self, ssa: 'SympySymbolAllocator') -> 'BloqCountDictT':
636639
return _KaliskiModInverseImpl(self.bitsize, self.mod).build_call_graph(ssa)
637640

qualtran/bloqs/mod_arithmetic/mod_division_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def test_kaliski_mod_inverse_classical_action(bitsize, mod):
4040
assert len(res) == 2
4141
assert res[0] == dtype.montgomery_inverse(x_montgomery, mod)
4242
assert dtype.montgomery_product(int(res[0]), x_montgomery, mod) == R
43+
assert blq.adjoint().call_classically(x=res[0], m=res[1]) == (x_montgomery,)
4344

4445

4546
@pytest.mark.parametrize('bitsize', [5, 6])

0 commit comments

Comments
 (0)