Skip to content

Commit cbc3727

Browse files
authored
add missing adjoints for basic gates (#895)
1 parent 91b80b1 commit cbc3727

4 files changed

Lines changed: 19 additions & 0 deletions

File tree

qualtran/bloqs/basic_gates/global_phase.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from typing import TYPE_CHECKING
1616

17+
import attrs
1718
import cirq
1819
from attrs import frozen
1920

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

48+
def adjoint(self) -> 'GlobalPhase':
49+
return attrs.evolve(self, coefficient=complex(self.coefficient).conjugate())
50+
4751
def pretty_name(self) -> str:
4852
return 'GPhase'
4953

qualtran/bloqs/basic_gates/su2_rotation.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ def build_composite_bloq(self, bb: 'BloqBuilder', q: 'SoquetT') -> Dict[str, 'So
131131
q = bb.add(ZPowGate(exponent=-self.phi / pi, global_shift=-1, eps=self.eps / 4), q=q)
132132
return {'q': q}
133133

134+
def adjoint(self) -> 'SU2RotationGate':
135+
return SU2RotationGate(
136+
theta=self.theta,
137+
phi=-self.lambd,
138+
lambd=-self.phi,
139+
global_shift=-self.global_shift,
140+
eps=self.eps,
141+
)
142+
134143
def pretty_name(self) -> str:
135144
return 'SU_2'
136145

qualtran/bloqs/basic_gates/swap.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def on_classical_vals(
102102
) -> Dict[str, 'ClassicalValT']:
103103
return {'x': y, 'y': x}
104104

105+
def adjoint(self) -> 'Bloq':
106+
return self
107+
105108

106109
@frozen
107110
class TwoBitCSwap(Bloq):

qualtran/bloqs/basic_gates/y_gate.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class YGate(Bloq):
4141
def signature(self) -> 'Signature':
4242
return Signature.build(q=1)
4343

44+
def adjoint(self) -> 'Bloq':
45+
return self
46+
4447
def add_my_tensors(
4548
self,
4649
tn: qtn.TensorNetwork,

0 commit comments

Comments
 (0)