Skip to content

Commit 6f378c0

Browse files
authored
Add some missing self-adjoints, use CtrlSpec instead of control_values (#1360)
* self adjoints * use ctrlspec
1 parent d5b615c commit 6f378c0

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

qualtran/bloqs/phase_estimation/qubitization_qpe.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818
import cirq
1919
import numpy as np
2020

21-
from qualtran import Bloq, bloq_example, BloqDocSpec, GateWithRegisters, Register, Signature
21+
from qualtran import (
22+
Bloq,
23+
bloq_example,
24+
BloqDocSpec,
25+
CtrlSpec,
26+
GateWithRegisters,
27+
Register,
28+
Signature,
29+
)
2230
from qualtran.bloqs.phase_estimation.qpe_window_state import QPEWindowStateBase
2331
from qualtran.bloqs.qft.qft_text_book import QFTTextBook
2432
from qualtran.bloqs.qubitization.qubitization_walk_operator import QubitizationWalkOperator
@@ -108,8 +116,8 @@ def decompose_from_registers(
108116
walk_regs = {reg.name: quregs[reg.name] for reg in self.walk.signature}
109117
reflect_regs = {reg.name: walk_regs[reg.name] for reg in self.walk.reflect.signature}
110118

111-
reflect_controlled = self.walk.reflect.controlled(control_values=[0])
112-
walk_controlled = self.walk.controlled(control_values=[1])
119+
reflect_controlled = self.walk.reflect.controlled(ctrl_spec=CtrlSpec(cvs=0))
120+
walk_controlled = self.walk.controlled()
113121

114122
qpre_reg = quregs['qpe_reg']
115123

@@ -128,8 +136,8 @@ def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']:
128136
M = 2**self.m_bits
129137
return {
130138
(self.ctrl_state_prep, 1),
131-
(self.walk.controlled(control_values=[1]), 1),
132-
(self.walk.reflect.controlled(control_values=[0]), 2 * (self.m_bits - 1)),
139+
(self.walk.controlled(), 1),
140+
(self.walk.reflect.controlled(ctrl_spec=CtrlSpec(cvs=0)), 2 * (self.m_bits - 1)),
133141
(self.walk, M - 2),
134142
(self.qft_inv, 1),
135143
}

qualtran/bloqs/reflections/prepare_identity.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def build_composite_bloq(self, bb: 'BloqBuilder', **soqs: Soquet) -> Dict[str, S
6767
soqs[label] = bb.add(Identity(soq.reg.bitsize), q=soq)
6868
return soqs
6969

70+
def adjoint(self) -> 'PrepareIdentity':
71+
return self
72+
7073

7174
@bloq_example(generalizer=ignore_split_join)
7275
def _prepare_identity() -> PrepareIdentity:

qualtran/bloqs/reflections/reflection_using_prepare.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']:
179179
costs.add((phase_op, 1))
180180
return costs
181181

182+
def adjoint(self) -> 'ReflectionUsingPrepare':
183+
return self
184+
182185

183186
@bloq_example(generalizer=ignore_split_join)
184187
def _refl_using_prep() -> ReflectionUsingPrepare:

0 commit comments

Comments
 (0)