Skip to content

Commit

Permalink
add missing adjoints for basic gates (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
anurudhp authored Apr 25, 2024
1 parent 91b80b1 commit cbc3727
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions qualtran/bloqs/basic_gates/global_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from typing import TYPE_CHECKING

import attrs
import cirq
from attrs import frozen

Expand Down Expand Up @@ -44,6 +45,9 @@ def cirq_gate(self) -> cirq.Gate:
def decompose_bloq(self) -> 'CompositeBloq':
raise DecomposeTypeError(f"{self} is atomic")

def adjoint(self) -> 'GlobalPhase':
return attrs.evolve(self, coefficient=complex(self.coefficient).conjugate())

def pretty_name(self) -> str:
return 'GPhase'

Expand Down
9 changes: 9 additions & 0 deletions qualtran/bloqs/basic_gates/su2_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ def build_composite_bloq(self, bb: 'BloqBuilder', q: 'SoquetT') -> Dict[str, 'So
q = bb.add(ZPowGate(exponent=-self.phi / pi, global_shift=-1, eps=self.eps / 4), q=q)
return {'q': q}

def adjoint(self) -> 'SU2RotationGate':
return SU2RotationGate(
theta=self.theta,
phi=-self.lambd,
lambd=-self.phi,
global_shift=-self.global_shift,
eps=self.eps,
)

def pretty_name(self) -> str:
return 'SU_2'

Expand Down
3 changes: 3 additions & 0 deletions qualtran/bloqs/basic_gates/swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def on_classical_vals(
) -> Dict[str, 'ClassicalValT']:
return {'x': y, 'y': x}

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


@frozen
class TwoBitCSwap(Bloq):
Expand Down
3 changes: 3 additions & 0 deletions qualtran/bloqs/basic_gates/y_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class YGate(Bloq):
def signature(self) -> 'Signature':
return Signature.build(q=1)

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

def add_my_tensors(
self,
tn: qtn.TensorNetwork,
Expand Down

0 comments on commit cbc3727

Please sign in to comment.