Skip to content

Commit 7e82d56

Browse files
msoekenpre-commit-ci[bot]nquetschlich
authored
Use local qsharp installation for RE experiments (#104)
This updates the RE_experiments.py sample to use a local installation instead of the service. The starting points are logical estimates extracted from the sample https://github.com/microsoft/qsharp/tree/main/samples/estimation/df-chemistry --------- Signed-off-by: Nils Quetschlich <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Nils Quetschlich <[email protected]>
1 parent 05ce0c1 commit 7e82d56

File tree

1 file changed

+55
-89
lines changed

1 file changed

+55
-89
lines changed
Lines changed: 55 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
from __future__ import annotations
22

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)
2333
params.error_budget = 0.01
2434
params.items[0].qubit_params.name = QubitParams.GATE_US_E3
2535
params.items[1].qubit_params.name = QubitParams.GATE_US_E4
@@ -30,66 +40,39 @@
3040
params.items[5].qubit_params.name = QubitParams.MAJ_NS_E6
3141
params.items[5].qec_scheme.name = QECScheme.FLOQUET_CODE
3242

33-
job = estimator.submit(df_chemistry(), input_params=params)
34-
results = job.get_results()
43+
results = logical_counts.estimate(params=params)
3544

3645
print()
3746
print("Default qubit models")
3847
print(results.summary_data_frame())
3948
print()
4049

50+
# --- Evaluating different number of T factories ---
4151

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)
6953
params.qubit_params.name = QubitParams.MAJ_NS_E6
7054
params.qec_scheme.name = QECScheme.FLOQUET_CODE
7155

7256
params.error_budget = 0.01
7357
for i in range(14):
7458
params.items[i].constraints.max_t_factories = 14 - i
7559

76-
job = estimator.submit(Main, input_params=params)
77-
results = job.get_results()
60+
results = logical_counts.estimate(params=params)
7861

7962
print()
8063
print("Different number of T factories")
8164
print(results.summary_data_frame())
8265
print()
8366

84-
### Modifying error rates and operating times
67+
# --- Modifying error rates and operating times ---
8568

8669
base_time = 50 # ns
8770
base_error = 1e-3
8871

8972
error_growth = 1e-1
9073
time_growth = 0.9
9174

92-
params = estimator.make_params(num_items=5)
75+
params = EstimatorParams(num_items=5)
9376
params.error_budget = 0.01
9477
for t in range(5):
9578
params.items[t].qubit_params.instruction_set = "gateBased"
@@ -104,56 +87,39 @@
10487
params.items[t].qubit_params.t_gate_error_rate = base_error * error_growth**t
10588
params.items[t].qubit_params.idle_error_rate = base_error * error_growth**t
10689

107-
job = estimator.submit(Main, input_params=params)
108-
results = job.get_results()
90+
results = logical_counts.estimate(params=params)
10991

11092
print()
11193
print("Modifying error rates and operating times")
11294
print(results.summary_data_frame())
11395
print()
11496

115-
### Modifying logical counts
116-
117-
program_with_args = f"""
118-
open Microsoft.Quantum.Math;
119-
open Microsoft.Quantum.ResourceEstimation;
97+
# --- Modifying logical counts ---
12098

121-
operation Main(spaceFactor : Double, timeFactor : Double) : Unit {{
122-
use qubits = Qubit[Ceiling(1369.0 * spaceFactor)];
12399

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+
)
137111

138-
MainWithArgs = qsharp.compile(program_with_args)
139112

140-
params = estimator.make_params(num_items=4)
113+
params = EstimatorParams()
141114
params.error_budget = 0.01
142115
params.qubit_params.name = QubitParams.MAJ_NS_E6
143116
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))
155121

156122
print()
157123
print("Modifying logical counts")
158-
print(results.summary_data_frame())
124+
print(EstimatorResult(estimates).summary_data_frame())
159125
print()

0 commit comments

Comments
 (0)