Skip to content

Commit

Permalink
Self adjoint for MCX and MCZ (#1502)
Browse files Browse the repository at this point in the history
* self adjoint for `MCX` and `MCZ`

* fix deprecated call graph in `SparseMatrixHermitian`
  • Loading branch information
anurudhp authored Dec 2, 2024
1 parent d92730e commit cb0d3c8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 5 additions & 4 deletions qualtran/bloqs/block_encoding/sparse_matrix_hermitian.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
from qualtran.bloqs.state_preparation.prepare_uniform_superposition import (
PrepareUniformSuperposition,
)
from qualtran.resource_counting import BloqCountT, SympySymbolAllocator
from qualtran.resource_counting import BloqCountDictT, SympySymbolAllocator
from qualtran.resource_counting.generalizers import ignore_split_join
from qualtran.symbolics import is_symbolic, SymbolicFloat, SymbolicInt
from qualtran.symbolics.math_funcs import bit_length

Expand Down Expand Up @@ -186,7 +187,7 @@ def diffusion(self):
],
)

def build_call_graph(self, ssa: SympySymbolAllocator) -> set[BloqCountT]:
def build_call_graph(self, ssa: SympySymbolAllocator) -> BloqCountDictT:
counts = Counter[Bloq]()

counts[self.diffusion] += 1
Expand All @@ -202,7 +203,7 @@ def build_call_graph(self, ssa: SympySymbolAllocator) -> set[BloqCountT]:
counts[self.col_oracle.adjoint()] += 1
counts[self.diffusion.adjoint()] += 1

return set(counts.items())
return counts

def build_composite_bloq(
self, bb: BloqBuilder, system: SoquetT, ancilla: SoquetT, **soqs
Expand Down Expand Up @@ -282,7 +283,7 @@ def build_composite_bloq(
return soqs


@bloq_example
@bloq_example(generalizer=ignore_split_join)
def _sparse_matrix_hermitian_block_encoding() -> SparseMatrixHermitian:
from qualtran.bloqs.block_encoding.sparse_matrix import TopLeftRowColumnOracle
from qualtran.bloqs.block_encoding.sparse_matrix_hermitian import UniformSqrtEntryOracle
Expand Down
6 changes: 6 additions & 0 deletions qualtran/bloqs/mcmt/multi_control_pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ def _X(self):
def __attrs_post_init__(self):
pass

def adjoint(self) -> 'Bloq':
return self


@bloq_example
def _ccpauli() -> MultiControlX:
Expand Down Expand Up @@ -233,3 +236,6 @@ def _Z(self):

def __attrs_post_init__(self):
pass

def adjoint(self) -> 'Bloq':
return self
3 changes: 1 addition & 2 deletions qualtran/bloqs/mod_arithmetic/mod_subtraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ def build_call_graph(self, ssa: 'SympySymbolAllocator') -> 'BloqCountDictT':
else:
cvs = HasLength(self.dtype.bitsize)
return {
MultiControlX(cvs): 1,
MultiControlX(cvs).adjoint(): 1,
MultiControlX(cvs): 2,
And(self.cv, 1): 1,
And(self.cv, 1).adjoint(): 1,
MultiTargetCNOT(self.dtype.bitsize): 1,
Expand Down

0 comments on commit cb0d3c8

Please sign in to comment.