Qualtran icon indicating copy to clipboard operation
Qualtran copied to clipboard

Use rotation `eps` in `GateCounts`

Open anurudhp opened this issue 1 year ago • 7 comments

fixes #1250

  • Maintain a frequency table of epsilons for rotation bloqs.
  • Epsilon is converted to a string (the dictionary key) using np.format_float_scientific, with a default precision of 10 digits.
  • T-costs:
    • Direct synthesis: 1.149 * log2(1.0 / eps) + 9.2 from https://arxiv.org/abs/1404.5320
    • Beverland et. al. model: passes the number of rotations, ignoring their epsilons.

anurudhp avatar Aug 06 '24 22:08 anurudhp

we had discussed binning by ceil(log(eps)) -- can you comment on that

mpharrigan avatar Aug 07 '24 13:08 mpharrigan

@tanujkhattar's comment:

It's better to store frequency of eps by assuming we can represent float eps as a fraction x / 2^{precision} and store frequencies of x; with precision as a configurable parameter in the constructor of QECGateCount class. It's also fine to store frequency of eps directly for now and make this change as a future improvement. I'd advice against storing frequency of ceil(log2(1/eps)) since it's a very aggressive approximation.

Binning by the above integer approximation can be implemented.

My bigger concern is the various epsilons floating around:

  • bloq.eps for rotation bloqs
  • error_budget in the surface code costing functions

Should we remove this error_budget and only use bloq.eps? I am not familiar enough with the surface_code implementation to decide if this is correct.

anurudhp avatar Aug 07 '24 17:08 anurudhp

Certain physical cost functions make certain assumptions, and we've tried to implement them as described in the literature. The coupling between the logical costs and the physical cost models is done -- in this case -- via the methods on GateCounts. So, since the beverland physical cost model just counts "rotations" and gives one third of the total error budget to synthesizing them, the get_beverland_counts method should just return the number of rotations in the appropriate field. The gidney-fowler models consume get_total_t_and_ccz_counts, which can use the per-gate epsilon values to turn it into t and ccz counts

mpharrigan avatar Aug 07 '24 17:08 mpharrigan

@mpharrigan ptal!

anurudhp avatar Aug 07 '24 23:08 anurudhp

taking a look now. Can you update the original PR description with a summary of changes in this pr

mpharrigan avatar Aug 08 '24 16:08 mpharrigan

The code snippet I was trying to use (which works with this PR):

import sympy
from qualtran.bloqs.basic_gates import ZPowGate
from qualtran.resource_counting import get_cost_value, QECGatesCost

t, eps = sympy.symbols(r"t \epsilon")
bloq = ZPowGate(exponent=t, eps=eps)
costs = get_cost_value(bloq, QECGatesCost())
costs.total_t_count()

anurudhp avatar Aug 08 '24 19:08 anurudhp

Thinking more about this, I think we'll need a special data container for the binned rotations that enforces the invariants we want to enforce. It's too dangerous to have our public data member be a dictionary whose keys are supposed to be strings crafted in a very particular way. (There's a secondary issue that a dictionary is mutable and therefore not compatible with the frozen GateCounts class)

mpharrigan avatar Aug 23 '24 17:08 mpharrigan