Skip to content
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

Generalize dispatcher for all job types #81

Merged
merged 11 commits into from
Dec 16, 2024
Merged

Generalize dispatcher for all job types #81

merged 11 commits into from
Dec 16, 2024

Conversation

cosenal
Copy link
Contributor

@cosenal cosenal commented Dec 14, 2024

Description

Generalizing the job dispatcher so that we don't need to create one for each job type.
Code specific to a job type should be created in the handlers.

Note: I will do the same for polling, but in a separate PR to make the PRs easier to digest.

Issue ticket number and link

Fixes #65

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Unit tests, plus smoke tested with

python metriq_gym/dispatch_job.py metriq_gym/schemas/examples/quantum_volume.example.json

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules (or not applicable)

@@ -0,0 +1,9 @@
from metriq_gym.benchmarks.benchmark import Benchmark
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of three separate imports from the same place, can we just have one that imports all three?

Suggested change
from metriq_gym.benchmarks.benchmark import Benchmark
from metriq_gym.benchmarks.benchmark import (
Benchmark,
CLOPS,
QuantumVolume,
)

Copy link
Contributor Author

@cosenal cosenal Dec 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now they are coming from three different modules, not from the same place. To achieve what you are suggesting, we would need to export them using __init__.py files, which I find it becomes unmanageable after a while.

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")


def main():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this in a main block? Can we take this out like so:

Suggested change
def main():
load_dotenv()
args = parse_arguments()
params = load_and_validate(args.input_file)
job_manager = JobManager(args.jobs_file)
HANDLERS[JobType(params["benchmark_name"])](args, params, job_manager).dispatch_handler()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to wrap it inside if __name__ == "__main__": so it's clear that it's a script meant to be run directly and not imported from other modules.
Note that this is going away as well at some point, and we will have only one cli script with a cli manager handling all the cli commands (Issue #56)

tests/test_schema_validator.py Outdated Show resolved Hide resolved
metriq_gym/dispatch_job.py Show resolved Hide resolved
from metriq_gym.job_manager import JobManager


class Benchmark:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this an abstract class? This would be a nice way to enforce that any subsequent benchmarks we implement have the dispatch and poll handlers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean a formal interface defined using abc.ABCMeta? It feels a bit over-engineering at the moment, given how small the codebase is. Also, until we migrate poll methods too, I wouldn't enforce the handler definition to be too strict.

metriq_gym/benchmarks/benchmark.py Show resolved Hide resolved
@cosenal cosenal requested a review from vprusso December 15, 2024 16:05
@cosenal cosenal merged commit 9c315cf into main Dec 16, 2024
1 check passed
@cosenal cosenal deleted the dispatch-decouple branch December 16, 2024 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generalize dispatch_bench_job function
2 participants