Skip to content

Commit d329f94

Browse files
authored
Merge pull request #92 from QuTech-Delft/fix-only-move-qubits-to-mem-if-has-memory-qubits
Add condition on moving qubits to memory to having memory qubits
2 parents aa621e5 + cc92385 commit d329f94

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

netqasm/sdk/builder.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,11 @@ def sdk_epr_keep(
19021902
and self._hardware_config.comm_qubit_count == 1
19031903
)
19041904

1905+
has_mem_qubits: bool = (
1906+
self._hardware_config is not None
1907+
and self._hardware_config.mem_qubit_count > 0
1908+
)
1909+
19051910
# If there is a post routine, handle pairs one by one.
19061911
# If there is only one comm qubit, handle pairs one by one.
19071912
if params.post_routine is not None or single_comm_qubit:
@@ -1929,7 +1934,7 @@ def sdk_epr_keep(
19291934
qubit_ids_array, ent_results_array, wait_all, params
19301935
)
19311936

1932-
if params.post_routine is None and single_comm_qubit:
1937+
if params.post_routine is None and single_comm_qubit and has_mem_qubits:
19331938
self._build_cmds_wait_move_epr_to_mem(
19341939
params=params, ent_results_array=ent_results_array, role=role
19351940
)

tests/test_builder.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from netqasm.lang.ir import BranchLabel, GenericInstr, ICmd, ProtoSubroutine
66
from netqasm.logging.glob import get_netqasm_logger
7-
from netqasm.sdk.build_types import NVHardwareConfig
7+
from netqasm.sdk.build_types import GenericHardwareConfig, NVHardwareConfig
88
from netqasm.sdk.connection import DebugConnection
99
from netqasm.sdk.constraint import ValueAtMostConstraint
1010
from netqasm.sdk.epr_socket import EPRSocket
@@ -1092,6 +1092,68 @@ def test_create_keep_no_corrections():
10921092
)
10931093

10941094

1095+
def test_create_keep_single_comm_qubit_no_memory_qubits():
1096+
"""
1097+
Check that if there is a single communication qubit, but no memory qubits,
1098+
the subroutine for creating an EPR pair does not contain a MOV instruction.
1099+
"""
1100+
DebugConnection.node_ids = {
1101+
"Alice": 0,
1102+
"Bob": 1,
1103+
}
1104+
1105+
epr_socket = EPRSocket("Bob")
1106+
1107+
with DebugConnection("Alice", epr_sockets=[epr_socket]) as conn:
1108+
conn.builder._hardware_config = GenericHardwareConfig(1)
1109+
1110+
epr_socket.create_keep(number=1)
1111+
1112+
subroutine = conn.builder.subrt_pop_pending_subroutine()
1113+
1114+
inspector = ProtoSubroutineInspector(subroutine)
1115+
assert inspector.match_pattern(
1116+
[
1117+
GenericInstr.CREATE_EPR,
1118+
GenericInstr.RET_ARR,
1119+
]
1120+
)
1121+
1122+
1123+
def test_create_keep_single_comm_qubit_has_memory_qubits():
1124+
"""
1125+
Check that if there is a single communication qubit and there are memory qubits,
1126+
the subroutine for creating an EPR pair does contain a MOV instruction.
1127+
"""
1128+
DebugConnection.node_ids = {
1129+
"Alice": 0,
1130+
"Bob": 1,
1131+
}
1132+
1133+
epr_socket = EPRSocket("Bob")
1134+
1135+
with DebugConnection("Alice", epr_sockets=[epr_socket]) as conn:
1136+
conn.builder._hardware_config = GenericHardwareConfig(1)
1137+
conn.builder._hardware_config._mem_qubit_count = 1
1138+
1139+
epr_socket.create_keep(number=1)
1140+
1141+
subroutine = conn.builder.subrt_pop_pending_subroutine()
1142+
1143+
inspector = ProtoSubroutineInspector(subroutine)
1144+
assert inspector.match_pattern(
1145+
[
1146+
GenericInstr.CREATE_EPR,
1147+
PatternWildcard.ANY_ZERO_OR_MORE,
1148+
GenericInstr.WAIT_ALL,
1149+
PatternWildcard.ANY_ZERO_OR_MORE,
1150+
GenericInstr.MOV,
1151+
PatternWildcard.ANY_ZERO_OR_MORE,
1152+
GenericInstr.RET_ARR,
1153+
]
1154+
)
1155+
1156+
10951157
def test_recv_keep_no_corrections():
10961158
DebugConnection.node_ids = {
10971159
"Alice": 0,

0 commit comments

Comments
 (0)