Skip to content

Commit

Permalink
now working as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
kessler-frost committed Nov 15, 2023
1 parent a321395 commit 4356068
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions covalent_dispatcher/_core/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}


Expand Down
16 changes: 6 additions & 10 deletions covalent_ui/api/v1/data_layer/electron_dal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions covalent_ui/api/v1/routes/end_points/electron_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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,
)


Expand Down

0 comments on commit 4356068

Please sign in to comment.