From 4356068b04efea58a8a310c5f38dd6543633cf42 Mon Sep 17 00:00:00 2001 From: Sankalp Sanand Date: Wed, 15 Nov 2023 02:15:41 -0500 Subject: [PATCH] now working as expected --- covalent_dispatcher/_core/data_manager.py | 3 +-- covalent_ui/api/v1/data_layer/electron_dal.py | 16 ++++++---------- .../api/v1/routes/end_points/electron_routes.py | 10 ++++++---- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/covalent_dispatcher/_core/data_manager.py b/covalent_dispatcher/_core/data_manager.py index 54cacc12e..a03a3df6b 100644 --- a/covalent_dispatcher/_core/data_manager.py +++ b/covalent_dispatcher/_core/data_manager.py @@ -44,7 +44,6 @@ log_stack_info = logger.log_stack_info -# TODO: Remove dispatch_id from the signature once qelectron_db becomes an Asset (PR #1690) def generate_node_result( node_id: int, node_name: str = None, @@ -86,7 +85,7 @@ def generate_node_result( "error": error, "stdout": stdout, "stderr": stderr, - "qelectron_data_exists": True, # TODO: Remove this after debugging + "qelectron_data_exists": qelectron_data_exists, # TODO: This field is now defunct, see PR #1850 } diff --git a/covalent_ui/api/v1/data_layer/electron_dal.py b/covalent_ui/api/v1/data_layer/electron_dal.py index 346d3f51e..fc8b92d2d 100644 --- a/covalent_ui/api/v1/data_layer/electron_dal.py +++ b/covalent_ui/api/v1/data_layer/electron_dal.py @@ -89,7 +89,7 @@ def get_jobs( return jobs_response try: jobs = self._get_qelectron_db_dict(str(dispatch_id), electron_id) - if not jobs: + if len(jobs) == 0: jobs_response.data = [] jobs_response.msg = f"Job details for {dispatch_id} dispatch with {electron_id} node do not exist." return jobs_response @@ -290,18 +290,14 @@ def get_electrons_id(self, dispatch_id, electron_id) -> Electron: ) return data - def get_total_quantum_calls(self, dispatch_id, node_id, is_qelectron: bool): - if not is_qelectron: - return None - + def get_total_quantum_calls(self, dispatch_id, node_id): qdb = self._get_qelectron_db_dict(dispatch_id=str(dispatch_id), node_id=node_id) - return len(qdb) - - def get_avg_quantum_calls(self, dispatch_id, node_id, is_qelectron: bool): - if not is_qelectron: - return None + return None if len(qdb) == 0 else len(qdb) + def get_avg_quantum_calls(self, dispatch_id, node_id): jobs = self._get_qelectron_db_dict(dispatch_id=str(dispatch_id), node_id=node_id) + if len(jobs) == 0: + return None time = [jobs[value]["execution_time"] for value in jobs] return sum(time) / len(time) diff --git a/covalent_ui/api/v1/routes/end_points/electron_routes.py b/covalent_ui/api/v1/routes/end_points/electron_routes.py index 03c2cf5dd..616f1c806 100644 --- a/covalent_ui/api/v1/routes/end_points/electron_routes.py +++ b/covalent_ui/api/v1/routes/end_points/electron_routes.py @@ -68,16 +68,18 @@ def get_electron_details(dispatch_id: uuid.UUID, electron_id: int): } ], ) + qelectron = { "total_quantum_calls": electron.get_total_quantum_calls( - dispatch_id, result["transport_graph_node_id"], result["qelectron_data_exists"] + dispatch_id, + result["transport_graph_node_id"], ), "avg_quantum_calls": electron.get_avg_quantum_calls( dispatch_id=dispatch_id, - is_qelectron=result["qelectron_data_exists"], node_id=result["transport_graph_node_id"], ), } + return ElectronResponse( id=result["id"], node_id=result["transport_graph_node_id"], @@ -90,8 +92,8 @@ def get_electron_details(dispatch_id: uuid.UUID, electron_id: int): ended_at=result["completed_at"], runtime=result["runtime"], description="", - qelectron_data_exists=bool(result["qelectron_data_exists"]), - qelectron=qelectron if bool(result["qelectron_data_exists"]) else None, + qelectron_data_exists=qelectron["total_quantum_calls"] is not None, + qelectron=qelectron if qelectron["total_quantum_calls"] is not None else None, )