Qualtran icon indicating copy to clipboard operation
Qualtran copied to clipboard

Incorrect gate counts for controlled gates

Open anurudhp opened this issue 1 year ago • 3 comments

Controlled bloqs do not have correct costs when the subbloq provides specialized controlled versions for only a subset of CtrlSpec.

from qualtran import CtrlSpec
from qualtran.bloqs.basic_gates import XGate
from qualtran.resource_counting import get_cost_value, QECGatesCost


def show_cost(bloq):
    cost = get_cost_value(bloq, QECGatesCost())
    print(f"{bloq} :: {cost}")


show_cost(XGate().controlled(CtrlSpec(cvs=(1, 1))))
show_cost(XGate().controlled(CtrlSpec(cvs=(1, 0))))
show_cost(XGate().controlled(CtrlSpec(cvs=(1, 1, 1))))
Toffoli :: toffoli: 1
C[2][XGate] :: -
C[3][XGate] :: -

anurudhp avatar Aug 15 '24 01:08 anurudhp

It's sortof impossible for it to know the accurate counts for a Controlled() atomic bloq.

But there's a bug nevertheless -- it shouldn't report successfully zero counts; it should raise an error

mpharrigan avatar Aug 20 '24 00:08 mpharrigan

How does the t_complexity protocol handle these?

mpharrigan avatar Aug 20 '24 01:08 mpharrigan

.t_complexity() raises a TypeError for the second and third examples.

anurudhp avatar Aug 20 '24 02:08 anurudhp

fixed in #1313 -- this will cause an error to be raised. Open follow-up issues for missing costs for Controlled(Atomic)

mpharrigan avatar Aug 23 '24 16:08 mpharrigan