Skip to content

Commit 55a7c37

Browse files
author
Bart van der Vecht
committed
first tests
1 parent 1a661f9 commit 55a7c37

File tree

2 files changed

+69
-15
lines changed

2 files changed

+69
-15
lines changed

examples/stack/partial_bqc/example_bqc_5_4.py

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from __future__ import annotations
22

33
import math
4+
import os
5+
import time
46
from typing import Any, Dict, Generator
57

8+
from netqasm.lang.parsing.text import parse_text_presubroutine
9+
610
from pydynaa import EventExpression
711
from squidasm.run.stack.config import (
812
GenericQDeviceConfig,
@@ -11,9 +15,17 @@
1115
StackNetworkConfig,
1216
)
1317
from squidasm.run.stack.run import run
18+
from squidasm.sim.stack.common import LogManager
1419
from squidasm.sim.stack.csocket import ClassicalSocket
1520
from squidasm.sim.stack.program import Program, ProgramContext, ProgramMeta
1621

22+
server_subrt_path = os.path.join(os.path.dirname(__file__), "server_5_4.nqasm")
23+
with open(server_subrt_path) as f:
24+
server_subrt_text = f.read()
25+
SERVER_SUBRT = parse_text_presubroutine(server_subrt_text)
26+
27+
USE_CUSTOM_SUBROUTINES = False
28+
1729

1830
class ClientProgram(Program):
1931
PEER = "server"
@@ -81,15 +93,33 @@ def run(
8193
yield from conn.flush()
8294

8395
delta1 = yield from csocket.recv_float()
96+
start = time.time() * 1e6
8497

85-
epr.rot_Z(angle=delta1)
86-
epr.H()
87-
m2 = epr.measure(store_array=False)
98+
if USE_CUSTOM_SUBROUTINES:
99+
SERVER_SUBRT.app_id = conn.app_id
100+
# print(SERVER_SUBRT.commands[1].operands)
101+
SERVER_SUBRT.commands[1].operands[1] = 3
102+
SERVER_SUBRT.commands[1].operands[2] = 1
103+
# for i in range(int(1e4)):
104+
# pass
105+
end = time.time() * 1e6
106+
yield from conn.commit_subroutine(SERVER_SUBRT)
107+
m2 = 0
108+
else:
109+
epr.rot_Z(angle=delta1)
110+
epr.H()
111+
m2 = epr.measure(store_array=False)
88112

89-
yield from conn.flush()
90-
m2 = int(m2)
113+
# for i in range(int(1e4)):
114+
# pass
115+
end = time.time() * 1e6
116+
117+
yield from conn.flush()
118+
m2 = int(m2)
91119

92-
return {"m2": m2}
120+
duration = end - start
121+
122+
return {"m2": m2, "duration": duration}
93123

94124

95125
def get_distribution(
@@ -106,17 +136,25 @@ def get_distribution(
106136
cfg, {"client": client_program, "server": server_program}, num_times
107137
)
108138

109-
m2s = [result["m2"] for result in server_results]
110-
num_zeros = len([m for m in m2s if m == 0])
111-
frac0 = round(num_zeros / num_times, 2)
112-
frac1 = 1 - frac0
113-
print(f"dist (0, 1) = ({frac0}, {frac1})")
139+
durations = [result["duration"] for result in server_results]
140+
# print(durations)
141+
142+
mean = round(sum(durations) / len(durations), 3)
143+
variance = sum((d - mean) * (d - mean) for d in durations) / len(durations)
144+
std_deviation = math.sqrt(variance)
145+
std_error = round(std_deviation / math.sqrt(len(durations)), 3)
146+
147+
max_dur = max(durations)
148+
min_dur = min(durations)
149+
150+
print(f"{mean}, {std_error} (max: {max_dur}, min: {min_dur})")
114151

115152

116153
PI = math.pi
117154
PI_OVER_2 = math.pi / 2
118155

119-
if __name__ == "__main__":
156+
157+
def main():
120158
num_times = 100
121159

122160
client_stack = StackConfig(
@@ -137,6 +175,11 @@ def get_distribution(
137175

138176
cfg = StackNetworkConfig(stacks=[client_stack, server_stack], links=[link])
139177

140-
get_distribution(cfg, num_times, alpha=0, theta1=0)
141-
get_distribution(cfg, num_times, alpha=PI, theta1=0)
142-
get_distribution(cfg, num_times, alpha=PI_OVER_2, theta1=0)
178+
get_distribution(cfg, num_times, alpha=PI_OVER_2, theta1=-PI)
179+
180+
181+
if __name__ == "__main__":
182+
USE_CUSTOM_SUBROUTINES = False
183+
main()
184+
USE_CUSTOM_SUBROUTINES = True
185+
main()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# NETQASM 1.0
2+
# APPID 0
3+
4+
set Q0 0
5+
rot_z Q0 3 1
6+
set Q0 0
7+
h Q0
8+
set Q0 0
9+
meas Q0 M0
10+
qfree Q0
11+
ret_reg M0

0 commit comments

Comments
 (0)