Qualtran
Qualtran copied to clipboard
Incorrect gate counts for controlled gates
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] :: -
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
How does the t_complexity protocol handle these?
.t_complexity() raises a TypeError for the second and third examples.
fixed in #1313 -- this will cause an error to be raised. Open follow-up issues for missing costs for Controlled(Atomic)