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

Add basic CLI around get_benchmark() #321

Merged
merged 9 commits into from
Apr 21, 2024
Merged

Conversation

ColoredCarrot
Copy link
Contributor

Mainly to be used automatically by tooling.
Options are simple CLI options for now, but should probably become more dynamic in the future (does argparse support dynamic/unregistered options?).

Copy link

codecov bot commented Apr 19, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 92.0%. Comparing base (60e1fa7) to head (2bc92c8).

Files Patch % Lines
src/mqt/bench/cli.py 94.4% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #321   +/-   ##
=====================================
  Coverage   91.9%   92.0%           
=====================================
  Files         46      47    +1     
  Lines       2406    2441   +35     
=====================================
+ Hits        2213    2246   +33     
- Misses       193     195    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@burgholzer burgholzer self-assigned this Apr 20, 2024
@burgholzer burgholzer added python Pull requests that update Python code usability Anything related to usability feature New feature or request labels Apr 20, 2024
Copy link
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

Hey 👋🏼
Many thanks for this first contribution! As discussed in other channels, this seems like a useful feature and the current PR is a solid basis for that.
I added some inline suggestions on some small improvements and some todos to make this feature complete. Those shouldn't really take long to incorporate.

(If you are not aware of that: if you go to the "Files changed" tab on GitHub, you can batch up suggestions into a single commit and apply them in one go directly from the web. This also resolves the related comments)

As already hinted at by the CLI, this PR is missing one more thing in addition to these small comments: test (coverage). There is a convenient way to test CLIs with unittests:

Those tests need not be massive, but they should cover the most common scenarios in which a user would run the CI.

Once those changes are implemented, this should be good to go and a really nice addition to the library. Many thanks 🙏🏼

src/mqt/bench/benchmark_generator.py Show resolved Hide resolved
src/mqt/bench/cli.py Show resolved Hide resolved
src/mqt/bench/cli.py Outdated Show resolved Hide resolved
src/mqt/bench/cli.py Outdated Show resolved Hide resolved
src/mqt/bench/cli.py Outdated Show resolved Hide resolved
src/mqt/bench/cli.py Outdated Show resolved Hide resolved
@ColoredCarrot
Copy link
Contributor Author

Re. tests: dumps(get_benchmark(...)) seems to yield non-deterministic results. I'm lacking the domain knowledge here; is there some easy way to verify that the printed QASM string corresponds to specific options?
If not, I'll just do some basic sanity checks (like these inputs should work and the result should contain "OPENQASM 2.0;" + these inputs shouldn't work).

@burgholzer
Copy link
Member

Re. tests: dumps(get_benchmark(...)) seems to yield non-deterministic results. I'm lacking the domain knowledge here; is there some easy way to verify that the printed QASM string corresponds to specific options?

If not, I'll just do some basic sanity checks (like these inputs should work and the result should contain "OPENQASM 2.0;" + these inputs shouldn't work).

Yeah. Some of the benchmarks involve steps that aren't very easy to seed for reproducibility. Thus, sometimes a check like comparing the result of the CLI with the result of the same get_benchmark call might fail.
However there should be some
Benchmarks that are fairly deterministic. Just at the top of my head:

  • the "ghz" benchmark should work deterministically under almost all settings
  • "shor" as a non-scalable example should be deterministic as well
  • given that the benchmarks with ancillary settings are handled similar to regular instances, there should be no need to test them here.

As stated in the comment at the top, the tests here really don't need to be too exhaustive. If the above helps to create a working set of tests, that should be fine 😌

Copy link
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

Many thanks for the additional changes and the quick workaround.
Everything looks good to me now!
Would really appreciate another PR resolving the special casing as discussed in the comment above!

@burgholzer burgholzer enabled auto-merge (squash) April 21, 2024 15:30
@burgholzer burgholzer merged commit f299681 into cda-tum:main Apr 21, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request python Pull requests that update Python code usability Anything related to usability
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants