|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -import os |
4 | | - |
5 | | -import qsharp |
6 | | -from azure.quantum import Workspace |
7 | | -from azure.quantum.chemistry import df_chemistry |
8 | | -from azure.quantum.target.microsoft import MicrosoftEstimator, QECScheme, QubitParams |
9 | | - |
10 | | -resource_id = os.environ.get("AZURE_QUANTUM_RESOURCE_ID") |
11 | | -location = os.environ.get("AZURE_QUANTUM_LOCATION") |
12 | | - |
13 | | -workspace = Workspace(resource_id=resource_id, location=location) |
14 | | -estimator = MicrosoftEstimator(workspace) |
15 | | - |
16 | | -### Default qubit models |
17 | | - |
18 | | -params = estimator.make_params(num_items=6) |
19 | | - |
20 | | -# select Hamiltonian |
21 | | -params.file_uris["fcidumpUri"] = "https://aka.ms/fcidump/XVIII-cas4-fb-64e-56o" |
22 | | - |
| 3 | +from math import ceil |
| 4 | + |
| 5 | +from qsharp.estimator import EstimatorParams, EstimatorResult, LogicalCounts, QECScheme, QubitParams |
| 6 | + |
| 7 | +# For all experiments, we are using the logical resource counts as a starting |
| 8 | +# point. These have been computed using the qsharp Python package (version |
| 9 | +# 1.8.0) for the https://aka.ms/fcidump/XVIII-cas4-fb-64e-56o Hamiltonian on |
| 10 | +# the sample |
| 11 | +# https://github.com/microsoft/qsharp/tree/main/samples/estimation/df-chemistry: |
| 12 | +# |
| 13 | +# ``` |
| 14 | +# $ python chemistry.py -f https://aka.ms/fcidump/XVIII-cas4-fb-64e-56o |
| 15 | +# $ jq '.logicalCounts' < resource_estimate.json |
| 16 | +# ``` |
| 17 | + |
| 18 | + |
| 19 | +logical_counts = LogicalCounts( |
| 20 | + { |
| 21 | + "numQubits": 1318, |
| 22 | + "tCount": 96, |
| 23 | + "rotationCount": 11987084, |
| 24 | + "rotationDepth": 11986482, |
| 25 | + "cczCount": 67474931068, |
| 26 | + "measurementCount": 63472407520, |
| 27 | + } |
| 28 | +) |
| 29 | + |
| 30 | +# --- Default qubit models --- |
| 31 | + |
| 32 | +params = EstimatorParams(6) |
23 | 33 | params.error_budget = 0.01 |
24 | 34 | params.items[0].qubit_params.name = QubitParams.GATE_US_E3 |
25 | 35 | params.items[1].qubit_params.name = QubitParams.GATE_US_E4 |
|
30 | 40 | params.items[5].qubit_params.name = QubitParams.MAJ_NS_E6 |
31 | 41 | params.items[5].qec_scheme.name = QECScheme.FLOQUET_CODE |
32 | 42 |
|
33 | | -job = estimator.submit(df_chemistry(), input_params=params) |
34 | | -results = job.get_results() |
| 43 | +results = logical_counts.estimate(params=params) |
35 | 44 |
|
36 | 45 | print() |
37 | 46 | print("Default qubit models") |
38 | 47 | print(results.summary_data_frame()) |
39 | 48 | print() |
40 | 49 |
|
| 50 | +# --- Evaluating different number of T factories --- |
41 | 51 |
|
42 | | -### Evaluating different number of T factories |
43 | | - |
44 | | -# For the next experiment, estimate from logical counts to save time |
45 | | -lcounts = results[0]["logicalCounts"] |
46 | | -program = f""" |
47 | | -open Microsoft.Quantum.ResourceEstimation; |
48 | | -
|
49 | | -operation Main() : Unit {{ |
50 | | - use qubits = Qubit[1369]; |
51 | | -
|
52 | | - AccountForEstimates( |
53 | | - [ |
54 | | - CczCount({lcounts["cczCount"] + lcounts["ccixCount"]}), |
55 | | - TCount({lcounts["tCount"]}), |
56 | | - RotationCount({lcounts["rotationCount"]}), |
57 | | - RotationDepth({lcounts["rotationDepth"]}), |
58 | | - MeasurementCount({lcounts["measurementCount"]}) |
59 | | - ], |
60 | | - PSSPCLayout(), |
61 | | - qubits |
62 | | - ); |
63 | | -}} |
64 | | -""" |
65 | | - |
66 | | -Main = qsharp.compile(program) |
67 | | - |
68 | | -params = estimator.make_params(num_items=14) |
| 52 | +params = EstimatorParams(num_items=14) |
69 | 53 | params.qubit_params.name = QubitParams.MAJ_NS_E6 |
70 | 54 | params.qec_scheme.name = QECScheme.FLOQUET_CODE |
71 | 55 |
|
72 | 56 | params.error_budget = 0.01 |
73 | 57 | for i in range(14): |
74 | 58 | params.items[i].constraints.max_t_factories = 14 - i |
75 | 59 |
|
76 | | -job = estimator.submit(Main, input_params=params) |
77 | | -results = job.get_results() |
| 60 | +results = logical_counts.estimate(params=params) |
78 | 61 |
|
79 | 62 | print() |
80 | 63 | print("Different number of T factories") |
81 | 64 | print(results.summary_data_frame()) |
82 | 65 | print() |
83 | 66 |
|
84 | | -### Modifying error rates and operating times |
| 67 | +# --- Modifying error rates and operating times --- |
85 | 68 |
|
86 | 69 | base_time = 50 # ns |
87 | 70 | base_error = 1e-3 |
88 | 71 |
|
89 | 72 | error_growth = 1e-1 |
90 | 73 | time_growth = 0.9 |
91 | 74 |
|
92 | | -params = estimator.make_params(num_items=5) |
| 75 | +params = EstimatorParams(num_items=5) |
93 | 76 | params.error_budget = 0.01 |
94 | 77 | for t in range(5): |
95 | 78 | params.items[t].qubit_params.instruction_set = "gateBased" |
|
104 | 87 | params.items[t].qubit_params.t_gate_error_rate = base_error * error_growth**t |
105 | 88 | params.items[t].qubit_params.idle_error_rate = base_error * error_growth**t |
106 | 89 |
|
107 | | -job = estimator.submit(Main, input_params=params) |
108 | | -results = job.get_results() |
| 90 | +results = logical_counts.estimate(params=params) |
109 | 91 |
|
110 | 92 | print() |
111 | 93 | print("Modifying error rates and operating times") |
112 | 94 | print(results.summary_data_frame()) |
113 | 95 | print() |
114 | 96 |
|
115 | | -### Modifying logical counts |
116 | | - |
117 | | -program_with_args = f""" |
118 | | -open Microsoft.Quantum.Math; |
119 | | -open Microsoft.Quantum.ResourceEstimation; |
| 97 | +# --- Modifying logical counts --- |
120 | 98 |
|
121 | | -operation Main(spaceFactor : Double, timeFactor : Double) : Unit {{ |
122 | | - use qubits = Qubit[Ceiling(1369.0 * spaceFactor)]; |
123 | 99 |
|
124 | | - AccountForEstimates( |
125 | | - [ |
126 | | - CczCount(Ceiling({lcounts["cczCount"] + lcounts["ccixCount"]}.0 * timeFactor)), |
127 | | - TCount(Ceiling({lcounts["tCount"]}.0 * timeFactor)), |
128 | | - RotationCount(Ceiling({lcounts["rotationCount"]}.0 * timeFactor)), |
129 | | - RotationDepth(Ceiling({lcounts["rotationDepth"]}.0 * timeFactor)), |
130 | | - MeasurementCount(Ceiling({lcounts["measurementCount"]}.0 * timeFactor)) |
131 | | - ], |
132 | | - PSSPCLayout(), |
133 | | - qubits |
134 | | - ); |
135 | | -}} |
136 | | -""" |
| 100 | +def modified_logical_counts(space_factor: float, time_factor: float): |
| 101 | + return LogicalCounts( |
| 102 | + { |
| 103 | + "numQubits": int(ceil(logical_counts["numQubits"] * space_factor)), |
| 104 | + "tCount": int(ceil(logical_counts["tCount"] * time_factor)), |
| 105 | + "rotationCount": int(ceil(logical_counts["rotationCount"] * time_factor)), |
| 106 | + "rotationDepth": int(ceil(logical_counts["rotationDepth"] * time_factor)), |
| 107 | + "cczCount": int(ceil(logical_counts["cczCount"] * time_factor)), |
| 108 | + "measurementCount": int(ceil(logical_counts["measurementCount"] * time_factor)), |
| 109 | + } |
| 110 | + ) |
137 | 111 |
|
138 | | -MainWithArgs = qsharp.compile(program_with_args) |
139 | 112 |
|
140 | | -params = estimator.make_params(num_items=4) |
| 113 | +params = EstimatorParams() |
141 | 114 | params.error_budget = 0.01 |
142 | 115 | params.qubit_params.name = QubitParams.MAJ_NS_E6 |
143 | 116 | params.qec_scheme.name = QECScheme.FLOQUET_CODE |
144 | | -params.items[0].arguments["spaceFactor"] = 1.0 |
145 | | -params.items[0].arguments["timeFactor"] = 1.0 |
146 | | -params.items[1].arguments["spaceFactor"] = 0.5 |
147 | | -params.items[1].arguments["timeFactor"] = 2.0 |
148 | | -params.items[2].arguments["spaceFactor"] = 2.0 |
149 | | -params.items[2].arguments["timeFactor"] = 0.5 |
150 | | -params.items[3].arguments["spaceFactor"] = 0.75 |
151 | | -params.items[3].arguments["timeFactor"] = 0.75 |
152 | | - |
153 | | -job = estimator.submit(MainWithArgs, input_params=params) |
154 | | -results = job.get_results() |
| 117 | +estimates = [] |
| 118 | +for space_factor, time_factor in [(1.0, 1.0), (0.5, 2.0), (2.0, 0.5), (0.75, 0.75)]: |
| 119 | + counts = modified_logical_counts(space_factor, time_factor) |
| 120 | + estimates.append(counts.estimate(params=params)) |
155 | 121 |
|
156 | 122 | print() |
157 | 123 | print("Modifying logical counts") |
158 | | -print(results.summary_data_frame()) |
| 124 | +print(EstimatorResult(estimates).summary_data_frame()) |
159 | 125 | print() |
0 commit comments