Qualtran icon indicating copy to clipboard operation
Qualtran copied to clipboard

Appropriate way to add on/off single controlled bloq?

Open fdmalone opened this issue 10 months ago • 6 comments

Is there a simpler way to add a singly-controlled bloq:

ctrl_spec = CtrlSpec(cvs=[0])
(ctrl,), q = bb.add(ZGate(), ctrl=(ctrl,), q=q)

seems a little awkward.

Is

ctrl_spec = CtrlSpec(QBit(), cvs=0b0)
ctrl, q = bb.add(ZGate(), ctrl=ctrl, q=q)

preferred?

fdmalone avatar Apr 18 '24 04:04 fdmalone

sorry, I don't fully understand your code snippets. Where are you using the ctrl_spec in either of them?

ctrl, q = bb.add(ZGate().controlled(), ctrl=ctrl, q=q)

would be how I would do it

mpharrigan avatar Apr 18 '24 23:04 mpharrigan

I want an off-control.

fdmalone avatar Apr 18 '24 23:04 fdmalone

Whoops, should have been:

ctrl_spec = CtrlSpec(cvs=[0])
(ctrl,), q = bb.add(ZGate().controlled(ctrl_spec), ctrl=(ctrl,), q=q)

and

ctrl_spec = CtrlSpec(QBit(), cvs=0b0)
ctrl, q = bb.add(ZGate().controlled(ctrl_spec), ctrl=ctrl, q=q)

fdmalone avatar Apr 18 '24 23:04 fdmalone

So you want a one-bit off-control. In the first one, you have to wrap your ctrl soquet in a lengh-1-list, which seems wrong and annoying. In the second one, you have to specify QBit(). You'd prefer something where you can just put cvs=0? Is this a correct summary of the issue?

mpharrigan avatar Apr 25 '24 17:04 mpharrigan

Right the second way seems a bit verbose. Very low priority though, just ran into it in #882

fdmalone avatar Apr 25 '24 18:04 fdmalone

Does it not work if you do CtrlSpec(cvs=0)? the default data type should be QBit(), no?

mpharrigan avatar May 01 '24 18:05 mpharrigan