Interop with Microsoft resource estimator#

Having interopability with Microsoft’s open-source resource estimator is useful because it allows users more flexiblity with their Qualtran programs and allows users to verify estimates given by Qualtran’s resource estimator tooling.

In this notebook, we will demonstrate doing resource estimation on the ModExp Bloq, the essential subroutine in Shor’s factoring algorithm.

from qualtran.bloqs.cryptography.rsa import ModExp
from qualtran.drawing import show_bloq

N = 13*17 # integer to factor
g = 8

mod_exp = ModExp(base=g, mod=N, exp_bitsize=32, x_bitsize=32)
show_bloq(mod_exp)
../_images/d5abfce1df43f259d56ca5fe884de3596636d975e816e4759fd1b10209f16b39.svg

In the next cell we have a function which takes in a Bloq and returns LogicalCounts, a python object which stores information about the logical data and gate counts. You can initialize the LogicalCounts object with a dictionary with information about your quantum algorithm. You can populate fields such as numQubits and tCount with information from a Qualtran Bloq as show below. For a more complete overview of the fields which you can specify in LogicalCounts, click here and look for the table which specifies the available functions with AccountForEstimates.

def get_bloq_logical_counts(bloq):
    from qsharp.estimator import LogicalCounts
    from qualtran._infra.gate_with_registers import get_named_qubits

    # This way of calculating the number of qubits will be inaccurate if a sub_bloq
    # allocates new qubits.
    num_qubits = bloq.signature.n_qubits()
    complexity = bloq.t_complexity()

    return LogicalCounts({
        "numQubits": num_qubits,
        "tCount": complexity.t,
        "rotationCount": complexity.rotations,
        "rotationDepth": complexity.rotations
    })

The LogicalCounts object has the key method, estimate, which returns an EstimatorResult which contains the physical resource estimates. By running the cell below, you can see a nice display of the physical resource estimates including runtime, physical qubits, and many more important resource estimates. For a more complete description of the EstimatorResult, click here.

estimates = get_bloq_logical_counts(mod_exp).estimate([
    {"qubitParams": {"name": "qubit_gate_ns_e3"}},
    {"qubitParams": {"name": "qubit_gate_ns_e4"}},
    {"qubitParams": {"name": "qubit_maj_ns_e4"}, "surfaceCode": {"name": "floquet_code"}},
    {"qubitParams": {"name": "qubit_maj_ns_e6"}, "surfaceCode": {"name": "floquet_code"}},
])

estimates
Physical resource estimates
Item0123
Runtime 11 secs 6 secs 45 secs 19 secs
rQOPS 18.10M 34.55M 4.47M 10.86M
Physical qubits 404.06k 72.42k 402.86k 24.90k
Resource estimates breakdown
Item0123
Logical algorithmic qubits 152 152 152 152
Algorithmic depth 1.33M 1.33M 1.33M 1.33M
Logical depth 1.33M 1.33M 1.33M 1.33M
Clock frequency 119.05k 227.27k 29.41k 71.43k
Number of T states 1.33M 1.33M 1.33M 1.33M
Number of T factories 15 11 15 10
Number of T factory invocations 88.95k 121.30k 88.95k 133.43k
Physical algorithmic qubits 134.06k 36.78k 87.86k 14.90k
Physical T factory qubits 270.00k 35.64k 315.00k 10.00k
Required logical qubit error rate 2.47e-12 2.47e-12 2.47e-12 2.47e-12
Required logical T state error rate 3.75e-10 3.75e-10 3.75e-10 3.75e-10
Number of T states per rotation No rotations in algorithm No rotations in algorithm No rotations in algorithm No rotations in algorithm
Logical qubit parameters
Item0123
QEC scheme surface_code surface_code surface_code surface_code
Code distance 21 11 17 7
Physical qubits 882 242 578 98
Logical cycle time 8 microsecs 4 microsecs 34 microsecs 14 microsecs
Logical qubit error rate 3.00e-13 3.00e-14 2.08e-12 1.58e-14
Crossing prefactor 0.03 0.03 0.08 0.08
Error correction threshold 0.01 0.01 0.0015 0.0015
Logical cycle time formula (4 * twoQubitGateTime + 2 * oneQubitMeasurementTime) * codeDistance (4 * twoQubitGateTime + 2 * oneQubitMeasurementTime) * codeDistance 20 * oneQubitMeasurementTime * codeDistance 20 * oneQubitMeasurementTime * codeDistance
Physical qubits formula 2 * codeDistance * codeDistance 2 * codeDistance * codeDistance 2 * codeDistance * codeDistance 2 * codeDistance * codeDistance
T factory parameters
Item0123
Physical qubits 18.00k 3.24k 21.00k 1.00k
Runtime 125 microsecs 47 microsecs 509 microsecs 132 microsecs
Number of output T states per run 1 1 1 1
Number of input T states per run 270 15 25.08k 345
Distillation rounds 2 1 3 2
Distillation units per round 18, 1 1 1672, 21, 1 23, 1
Distillation units 15-to-1 space efficient, 15-to-1 space efficient 15-to-1 space efficient 15-to-1 space efficient, 15-to-1 space efficient, 15-to-1 RM prep 15-to-1 RM prep, 15-to-1 space efficient
Distillation code distances 5, 19 9 1, 5, 17 1, 5
Number of physical qubits per round 18.00k, 14.44k 3.24k 20.06k, 21.00k, 17.92k 713, 1.00k
Runtime per round 26 microsecs, 99 microsecs 47 microsecs 5 microsecs, 130 microsecs, 374 microsecs 2 microsecs, 130 microsecs
Logical T state error rate 3.60e-10 5.63e-11 1.96e-10 1.71e-10
Pre-layout logical resources
Item0123
Logical qubits (pre-layout) 64 64 64 64
T gates 1.33M 1.33M 1.33M 1.33M
Rotation gates 0 0 0 0
Rotation depth 0 0 0 0
CCZ gates 0 0 0 0
CCiX gates 0 0 0 0
Measurement operations 0 0 0 0
Assumed error budget
Item0123
Total error budget 1.00e-3 1.00e-3 1.00e-3 1.00e-3
Logical error probability 5.00e-4 5.00e-4 5.00e-4 5.00e-4
T distillation error probability 5.00e-4 5.00e-4 5.00e-4 5.00e-4
Rotation synthesis error probability 0.00e0 0.00e0 0.00e0 0.00e0
Physical qubit parameters
Item0123
Qubit name qubit_gate_ns_e3 qubit_gate_ns_e4 qubit_maj_ns_e4 qubit_maj_ns_e6
Instruction set GateBased GateBased Majorana Majorana
Single-qubit measurement time 100 ns 100 ns 100 ns 100 ns
Single-qubit gate time 50 ns 50 ns N/A N/A
Two-qubit gate time 50 ns 50 ns N/A N/A
T gate time 50 ns 50 ns 100 ns 100 ns
Single-qubit measurement error rate 0.001 0.0001 {'process': 0.0001, 'readout': 0.0001} {'process': 1e-06, 'readout': 1e-06}
Single-qubit error rate 0.001 0.0001 N/A N/A
Two-qubit error rate 0.001 0.0001 N/A N/A
T gate error rate 0.001 0.0001 0.05 0.01
Two-qubit measurement time N/A N/A 100 ns 100 ns
Two-qubit measurement error rate N/A N/A {'process': 0.0001, 'readout': 0.0001} {'process': 1e-06, 'readout': 1e-06}
Constraints
Item0123
Logical depth factor constraint not set constraint not set constraint not set constraint not set
Maximum number of T factories constraint not set constraint not set constraint not set constraint not set
Maximum runtime duration constraint not set constraint not set constraint not set constraint not set
Maximum number of physical qubits constraint not set constraint not set constraint not set constraint not set
Assumptions

    You can display more complex UIs on top of estimates with qsharp_widgets. For example, the code below displays a chart with information on the physical qubit counts. To learn more about using qsharp_widgets to create other informative graphics such as a Space-time diagram, click here.

    from qsharp_widgets import SpaceChart
    SpaceChart(estimates)