Skip to content

Commit

Permalink
Bitwise bloqs are self adjoint (#1220)
Browse files Browse the repository at this point in the history
bitwise bloqs are self adjoint
  • Loading branch information
anurudhp authored Jul 30, 2024
1 parent 2a78ca1 commit f9071c8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions qualtran/bloqs/arithmetic/bitwise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"## `Xor`\n",
"Xor the value of one register into another via CNOTs.\n",
"\n",
"Maps basis states $|x, y\\rangle$ to $|x, y \\oplus x\\rangle$.\n",
"\n",
"When both registers are in computational basis and the destination is 0,\n",
"effectively copies the value of the source into the destination.\n",
"\n",
Expand Down
13 changes: 12 additions & 1 deletion qualtran/bloqs/arithmetic/bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def bitsize(self) -> SymbolicInt:
def is_symbolic(self):
return is_symbolic(self.k, self.dtype)

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

@cached_property
def _bits_k(self) -> Sequence[int]:
return self.dtype.to_bits(self.k)
Expand Down Expand Up @@ -116,7 +119,9 @@ def _xork() -> XorK:

@frozen
class Xor(Bloq):
"""Xor the value of one register into another via CNOTs.
r"""Xor the value of one register into another via CNOTs.
Maps basis states $|x, y\rangle$ to $|x, y \oplus x\rangle$.
When both registers are in computational basis and the destination is 0,
effectively copies the value of the source into the destination.
Expand All @@ -135,6 +140,9 @@ class Xor(Bloq):
def signature(self) -> Signature:
return Signature.build_from_dtypes(x=self.dtype, y=self.dtype)

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

def build_composite_bloq(self, bb: BloqBuilder, x: Soquet, y: Soquet) -> dict[str, SoquetT]:
if not isinstance(self.dtype.num_qubits, int):
raise DecomposeTypeError("`dtype.num_qubits` must be a concrete value.")
Expand Down Expand Up @@ -202,6 +210,9 @@ class BitwiseNot(Bloq):
def signature(self) -> 'Signature':
return Signature.build_from_dtypes(x=self.dtype)

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

def build_composite_bloq(self, bb: 'BloqBuilder', x: 'Soquet') -> dict[str, 'SoquetT']:
x = bb.add(OnEach(self.dtype.num_qubits, XGate()), q=x)
return {'x': x}
Expand Down

0 comments on commit f9071c8

Please sign in to comment.