-
Notifications
You must be signed in to change notification settings - Fork 0
Implement Job Metrics and its APIs #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bmete7
wants to merge
11
commits into
develop
Choose a base branch
from
tvb-bm/feat/circuit_metrics_table
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
64a7d7e
:sparkles: implement timestamp_data table
Bmete7 9a993bc
fixed table creation
ec581d2
:see_no_evil: added local development related files
Bmete7 9e86d4b
:bug: id added as a primary key
Bmete7 3b8cca3
:art: renamed class to lowercase letters
Bmete7 8f140b1
:bug: seperate job_metrics as a new component
Bmete7 1891fce
:bug: refactor database creation to handle unfilled job metric entrie…
Bmete7 360b369
:recycle: adress review comments, change the name of the fetch method…
Bmete7 412b482
🐛 passes_applied should be text
kalliope192 36ffaf2
resolve unittest-issues resulting from rebase
kalliope192 a24411a
bump version
kalliope192 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| """This module contains all helpers related to job metrics for resources in the database.""" | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| from pony.orm import db_session # type: ignore | ||
|
|
||
| from ._database import open_database | ||
|
|
||
|
|
||
| @db_session | ||
| def fill_job_metrics(job_id: int, metrics: dict) -> None: | ||
| """Given the job_id and metrics, fill the new TimestampData table. | ||
| This is being called by the | ||
|
|
||
| Args: | ||
| job_id (int): uuid of the circuit jobs | ||
| metrics (dict): Dictionary of the runtime metrics | ||
| """ | ||
| quantum_db = open_database() | ||
|
|
||
| job = quantum_db.TimestampData.get(id=job_id) | ||
|
|
||
| if job is None: | ||
| return | ||
|
|
||
| # list of timestamp attribute names on the TimestampData entity | ||
| timestamp_attrs = [ | ||
| "api_entry", | ||
| "api_exit", | ||
| "qdb_entry", | ||
| "qdb_exit", | ||
| "qjr_entry", | ||
| "qjr_exit", | ||
| "isv_jr_entry", | ||
| "isv_jr_exit", | ||
| "quantum_daemon_jr_entry", | ||
| "quantum_daemon_jr_exit", | ||
| "generator_entry", | ||
| "generator_exit", | ||
| "scheduler_entry", | ||
| "scheduler_exit", | ||
| "pass_runner_entry", | ||
| "pass_runner_exit", | ||
| "passes_applied", | ||
| "transpiler_entry", | ||
| "transpiler_exit", | ||
| "submitter_entry", | ||
| "submitter_exit", | ||
| "pass_selection_entry", | ||
| "pass_selection_exit", | ||
| "knitter_entry", | ||
| "knitter_exit", | ||
| "job_execution_start", | ||
| "job_execution_end", | ||
| ] | ||
|
|
||
| for attr in timestamp_attrs: | ||
| match_key = next((k for k in metrics.keys() if k.lower() == attr.lower()), None) | ||
| if match_key is None: | ||
| continue | ||
| value = metrics.get(match_key) | ||
| if value is None: | ||
| continue | ||
| try: | ||
| setattr(job, attr, value) | ||
| except Exception: | ||
| continue | ||
|
|
||
| quantum_db.commit() | ||
|
|
||
|
|
||
| @db_session | ||
| def update_timestamp_data_submitted(id: str) -> None: | ||
| """Fills the timestamp_completed field of the TimestampData table, since | ||
| that information is already filled on the CircuitJob table. | ||
|
|
||
| Args: | ||
| id (str): job id of a CircuitJob. | ||
| """ | ||
| quantum_db = open_database() | ||
|
|
||
| jobs = list( | ||
| quantum_db.CircuitJob.select(status="COMPLETED").filter( | ||
| lambda job: (job.id == id) | ||
| ) | ||
| ) | ||
| timestamp_job = quantum_db.TimestampData.get(id=id) | ||
| timestamp_job.job_execution_end = jobs.timestamp_completed | ||
|
|
||
|
|
||
| @db_session | ||
| def fetch_timestamp_data_by_job_id( | ||
| id: str, | ||
| ) -> list["TimestampData"] | None: | ||
| quantum_db = open_database() | ||
|
|
||
| try: | ||
| query = quantum_db.TimestampData.select(id=id) | ||
| job = list(query) | ||
| except Exception as e: | ||
| print("Job metrics cannot be found (or not specifed) for this job") | ||
| return None | ||
| if not job: | ||
| print(f"Job metrics cannot be found (or not specified) for this job") | ||
| return None | ||
| return job |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.