Skip to content

Commit

Permalink
Override KaliskiModInverse.adjoint (#1483)
Browse files Browse the repository at this point in the history
NoureldinYosri authored Oct 31, 2024
1 parent bc155b6 commit baad879
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion qualtran/bloqs/mod_arithmetic/mod_division.py
Original file line number Diff line number Diff line change
@@ -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)

1 change: 1 addition & 0 deletions qualtran/bloqs/mod_arithmetic/mod_division_test.py
Original file line number Diff line number Diff line change
@@ -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])

0 comments on commit baad879

Please sign in to comment.