diff --git a/qualtran/bloqs/mod_arithmetic/mod_division.py b/qualtran/bloqs/mod_arithmetic/mod_division.py index d5bad9fc1..575a1aada 100644 --- a/qualtran/bloqs/mod_arithmetic/mod_division.py +++ b/qualtran/bloqs/mod_arithmetic/mod_division.py @@ -17,7 +17,7 @@ import numpy as np import sympy -from attrs import frozen +from attrs import evolve, frozen from qualtran import ( Bloq, @@ -632,6 +632,9 @@ def build_composite_bloq( bb.free(f) return {'x': x, 'm': m} + def adjoint(self) -> 'KaliskiModInverse': + return evolve(self, uncompute=not self.uncompute) + def build_call_graph(self, ssa: 'SympySymbolAllocator') -> 'BloqCountDictT': return _KaliskiModInverseImpl(self.bitsize, self.mod).build_call_graph(ssa) diff --git a/qualtran/bloqs/mod_arithmetic/mod_division_test.py b/qualtran/bloqs/mod_arithmetic/mod_division_test.py index 31c56d394..02646ef82 100644 --- a/qualtran/bloqs/mod_arithmetic/mod_division_test.py +++ b/qualtran/bloqs/mod_arithmetic/mod_division_test.py @@ -40,6 +40,7 @@ def test_kaliski_mod_inverse_classical_action(bitsize, mod): assert len(res) == 2 assert res[0] == dtype.montgomery_inverse(x_montgomery, mod) assert dtype.montgomery_product(int(res[0]), x_montgomery, mod) == R + assert blq.adjoint().call_classically(x=res[0], m=res[1]) == (x_montgomery,) @pytest.mark.parametrize('bitsize', [5, 6])