From 80015f4769666d5b00f892d3fff30f17306b8475 Mon Sep 17 00:00:00 2001 From: mvanhooft Date: Thu, 18 Dec 2025 14:24:01 +0100 Subject: [PATCH 1/3] Add condition on moving qubits to memory to having memory qubits --- netqasm/sdk/builder.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/netqasm/sdk/builder.py b/netqasm/sdk/builder.py index b076f5ff..e4db8891 100644 --- a/netqasm/sdk/builder.py +++ b/netqasm/sdk/builder.py @@ -1902,6 +1902,11 @@ def sdk_epr_keep( and self._hardware_config.comm_qubit_count == 1 ) + has_mem_qubits: bool = ( + self._hardware_config is not None + and self._hardware_config.mem_qubit_count > 0 + ) + # If there is a post routine, handle pairs one by one. # If there is only one comm qubit, handle pairs one by one. if params.post_routine is not None or single_comm_qubit: @@ -1929,7 +1934,7 @@ def sdk_epr_keep( qubit_ids_array, ent_results_array, wait_all, params ) - if params.post_routine is None and single_comm_qubit: + if params.post_routine is None and single_comm_qubit and has_mem_qubits: self._build_cmds_wait_move_epr_to_mem( params=params, ent_results_array=ent_results_array, role=role ) From 7e0a1b1c1524a8690aaf53b8c03a3fea950a1b75 Mon Sep 17 00:00:00 2001 From: mvanhooft Date: Thu, 18 Dec 2025 14:27:38 +0100 Subject: [PATCH 2/3] Linter fix --- netqasm/sdk/builder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netqasm/sdk/builder.py b/netqasm/sdk/builder.py index e4db8891..efae30fc 100644 --- a/netqasm/sdk/builder.py +++ b/netqasm/sdk/builder.py @@ -1903,8 +1903,8 @@ def sdk_epr_keep( ) has_mem_qubits: bool = ( - self._hardware_config is not None - and self._hardware_config.mem_qubit_count > 0 + self._hardware_config is not None + and self._hardware_config.mem_qubit_count > 0 ) # If there is a post routine, handle pairs one by one. From cc923851b0c632b1200fe9d5aca7fe5530abb6fd Mon Sep 17 00:00:00 2001 From: mvanhooft Date: Mon, 12 Jan 2026 11:45:14 +0100 Subject: [PATCH 3/3] Create two tests to check correct conditions of a MOV instruction after EPR creation * One test that no MOV is made if no memory qubits are available * Other test for check that a MOV is made if memory qubits are available --- tests/test_builder.py | 64 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/tests/test_builder.py b/tests/test_builder.py index 289a3a59..5c51af22 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -4,7 +4,7 @@ from netqasm.lang.ir import BranchLabel, GenericInstr, ICmd, ProtoSubroutine from netqasm.logging.glob import get_netqasm_logger -from netqasm.sdk.build_types import NVHardwareConfig +from netqasm.sdk.build_types import GenericHardwareConfig, NVHardwareConfig from netqasm.sdk.connection import DebugConnection from netqasm.sdk.constraint import ValueAtMostConstraint from netqasm.sdk.epr_socket import EPRSocket @@ -1092,6 +1092,68 @@ def test_create_keep_no_corrections(): ) +def test_create_keep_single_comm_qubit_no_memory_qubits(): + """ + Check that if there is a single communication qubit, but no memory qubits, + the subroutine for creating an EPR pair does not contain a MOV instruction. + """ + DebugConnection.node_ids = { + "Alice": 0, + "Bob": 1, + } + + epr_socket = EPRSocket("Bob") + + with DebugConnection("Alice", epr_sockets=[epr_socket]) as conn: + conn.builder._hardware_config = GenericHardwareConfig(1) + + epr_socket.create_keep(number=1) + + subroutine = conn.builder.subrt_pop_pending_subroutine() + + inspector = ProtoSubroutineInspector(subroutine) + assert inspector.match_pattern( + [ + GenericInstr.CREATE_EPR, + GenericInstr.RET_ARR, + ] + ) + + +def test_create_keep_single_comm_qubit_has_memory_qubits(): + """ + Check that if there is a single communication qubit and there are memory qubits, + the subroutine for creating an EPR pair does contain a MOV instruction. + """ + DebugConnection.node_ids = { + "Alice": 0, + "Bob": 1, + } + + epr_socket = EPRSocket("Bob") + + with DebugConnection("Alice", epr_sockets=[epr_socket]) as conn: + conn.builder._hardware_config = GenericHardwareConfig(1) + conn.builder._hardware_config._mem_qubit_count = 1 + + epr_socket.create_keep(number=1) + + subroutine = conn.builder.subrt_pop_pending_subroutine() + + inspector = ProtoSubroutineInspector(subroutine) + assert inspector.match_pattern( + [ + GenericInstr.CREATE_EPR, + PatternWildcard.ANY_ZERO_OR_MORE, + GenericInstr.WAIT_ALL, + PatternWildcard.ANY_ZERO_OR_MORE, + GenericInstr.MOV, + PatternWildcard.ANY_ZERO_OR_MORE, + GenericInstr.RET_ARR, + ] + ) + + def test_recv_keep_no_corrections(): DebugConnection.node_ids = { "Alice": 0,