From 3fe0b9c057d8fa09a0b989047f66bd04f7c76ef4 Mon Sep 17 00:00:00 2001 From: Maxim V4S Date: Wed, 15 Jan 2025 10:26:06 +0300 Subject: [PATCH 1/2] fix: use class var active node for stopping --- qualibrate/qualibration_node.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/qualibrate/qualibration_node.py b/qualibrate/qualibration_node.py index 4bbdd3c..108727b 100644 --- a/qualibrate/qualibration_node.py +++ b/qualibrate/qualibration_node.py @@ -101,6 +101,7 @@ class QualibrationNode( storage_manager: Optional[ StorageManager["QualibrationNode[NodeParameters]"] ] = None + active_node: Optional["QualibrationNode[ParametersType]"] = None def __init__( self, @@ -129,7 +130,9 @@ def __init__( raise StopInspection( "Node instantiated in inspection mode", instance=self ) - + if name == "wf_node1": + print("init", id(self)) + self.__class__.active_node = self last_executed_node_ctx.set(self) self._warn_if_external_and_interactive_mpl() @@ -605,14 +608,20 @@ def stop(self, **kwargs: Any) -> bool: Returns: True if the node is successfully stopped, False otherwise. """ - logger.debug(f"Stop node {self.name}") + active_node = self.__class__.active_node + print("stop", id(active_node)) + if active_node is None: + return False + logger.debug(f"Stop node {active_node.name}") if find_spec("qm") is None: return False - qmm = getattr(self.machine, "qmm", None) + qmm = getattr(active_node.machine, "qmm", None) if not qmm: - if self.machine is None or not hasattr(self.machine, "connect"): + if active_node.machine is None or not hasattr( + active_node.machine, "connect" + ): return False - qmm = self.machine.connect() + qmm = active_node.machine.connect() if hasattr(qmm, "list_open_qms"): ids = qmm.list_open_qms() elif hasattr(qmm, "list_open_quantum_machines"): From c63d49fae8867b6e507ff231e1a163ec634df858 Mon Sep 17 00:00:00 2001 From: Maxim V4S Date: Wed, 15 Jan 2025 16:30:03 +0300 Subject: [PATCH 2/2] refactor: remove debug print --- qualibrate/qualibration_node.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/qualibrate/qualibration_node.py b/qualibrate/qualibration_node.py index 108727b..03f30bc 100644 --- a/qualibrate/qualibration_node.py +++ b/qualibrate/qualibration_node.py @@ -130,8 +130,6 @@ def __init__( raise StopInspection( "Node instantiated in inspection mode", instance=self ) - if name == "wf_node1": - print("init", id(self)) self.__class__.active_node = self last_executed_node_ctx.set(self) @@ -609,10 +607,10 @@ def stop(self, **kwargs: Any) -> bool: True if the node is successfully stopped, False otherwise. """ active_node = self.__class__.active_node - print("stop", id(active_node)) + logger.debug(f"Stop node {active_node} with id {id(active_node)}") if active_node is None: return False - logger.debug(f"Stop node {active_node.name}") + logger.info(f"Stop node {active_node.name}") if find_spec("qm") is None: return False qmm = getattr(active_node.machine, "qmm", None)