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 script to compare commits and additional benchmarks #568
Conversation
Codecov Report
@@ Coverage Diff @@
## master #568 +/- ##
=======================================
Coverage 98.92% 98.92%
=======================================
Files 82 82
Lines 5124 5124
=======================================
Hits 5069 5069
Misses 55 55 Continue to review full report at Codecov.
|
This will be a great tool @johannesjmeyer! |
I'm curious about some of the underlying logic. This script only works for revisions which are on the remote server, correct? It doesn't seem to recognize any commits/branches I have locally |
I now also fixed some other git stuff that caused the wrong revision to be downloaded and that fixed the download of revisions that are "too new". @co9olguy Yes, the script only runs for revisions on the remote server. I wouldn't necessarily know where to look on your local machine. One could of course add this possibility and give a directory, but I don't think that this merits the work @josh146 I didn't put it into |
Since you mentioned above that the benchmark should be run out of the pennylane "mother" directory, and that will always be itself a |
Yes, I will add "here" as a special command that uses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks @johannesjmeyer, looking forward to giving this tool some use :)
Everything is now working as advertised. The only thing I wonder is if it is necessary to create separate folders for every revision during testing. Couldn't we make one folder (or perhaps just use the "mother" folder!), then just use git
to switch between the different commits?
benchmark/README.rst
Outdated
|
||
python3 benchmark_revisions.py -r master,0c8e90a -d default.qubit,default.tensor time bm_mutable_rotations | ||
|
||
The chosen revisions will be downloaded and cached into the ``revisions`` subdirectory of the benchmarking folder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now goes to home directory, correct?
benchmark/benchmark_revisions.py
Outdated
# PL repository. Instead we just copy the first revision in the directory | ||
# checkout will then get the correct revision | ||
first_revision = next((x for x in revisions_directory.iterdir() if x.is_dir())) | ||
print(">>> Revision not found locally, copying...") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(">>> Revision not found locally, copying...") | |
print(">>> Revision found locally, copying...") |
benchmark/benchmark_revisions.py
Outdated
revision, | ||
"-q", | ||
], | ||
check=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what allowed me to figure out the --noinfo
error I was seeing. Otherwise I think it would have silently failed
benchmark/benchmark_revisions.py
Outdated
with cd(pl_directory): | ||
subprocess.run(["git", "checkout", "master", "-q"], check=True) | ||
subprocess.run(["git", "fetch", "-q"], check=True) | ||
res = subprocess.run(["git", "checkout", revision, "-q"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no check=True
here? Is that because you want to inspect res.returncode
below?
benchmark/benchmark_revisions.py
Outdated
benchmark_env = os.environ.copy() | ||
benchmark_env["PYTHONPATH"] = str(pl_directory) + ";" + benchmark_env["PATH"] | ||
subprocess.run( | ||
["python3", str(benchmark_file_path)] + unknown_args + ["--noinfo"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so "--noinfo" is always turned on for benchmarking revisions?
benchmark/benchmark_revisions.py
Outdated
print( | ||
col( | ||
">>> An error occured during execution of the script. " | ||
+ "Deleting the current revision folder to not leave junk.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ "Deleting the current revision folder to not leave junk.", | |
+ "Deleting the current revision folder.", |
benchmark/benchmark_revisions.py
Outdated
env=benchmark_env, | ||
check=True, | ||
) | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will section ever get with check=True
? (I'm not too experienced with using subprocess.run
, just checking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! 🚀 Thanks @johannesjmeyer
Co-Authored-By: Nathan Killoran <co9olguy@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, and tested locally and still works well :)
The revisions -- including branches, tags and commits -- are specified via ``-r revision1[,revision2[,revision3...]]``, | ||
as in | ||
|
||
.. code-block:: bash | ||
|
||
python3 benchmark_revisions.py -r master,0c8e90a -d default.qubit,default.tensor time bm_mutable_rotations | ||
|
||
The chosen revisions will be downloaded and cached into the ``revisions`` subdirectory of the benchmarking folder. | ||
The chosen revisions will be downloaded and cached into the ``pennylane.benchmark/revisions`` subdirectory of your user home directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it's now .pennylane/benchmarks/revisions
?
Thanks @johannesjmeyer, i am happy to merge this in (I had already approved). Not something that's important for this PR, but I'm still a bit puzzled why we can't just perform the benchmarking in-place. What is the requirement that forces us to create the new folder |
I guess the primary reason is that we wouldn't be able to test any commits that didn't yet have the |
# Make really sure we don't reset the current git | ||
if toplevel == Path.cwd(): | ||
raise Exception( | ||
"Git accidently ended up in the current directory. Stopping to not cause any harm." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 🚀
Nice, working as before! 😉 👍 |
No, actually my principal reason is that I really don't want to mess with the current git. I mean, we could surely implement some logic that stashes pending changes if there are some and then recovers them. But imagine there is some error during the script execution and your changes are gone. So I figured it is better to do it in a sandboxed environment. Also PennyLane source is 43MB, this is not hurting anyone. |
Context:
The PR #567 needs some tests to see if it works.
Description of the Change:
This PR introduces a script to benchmark across commits.
Furthermore it adds new benchmarks.
There now exists a script
benchmark_revisions.py
that accepts a list of git revisions (i.e. branches, tags or commits). It downloads those commits and then runsbenchmark.py
with all the other parameters it got using the downloaded revision of pennylane.Revisions are stored to decrease the number of necessary downloads.
Furthermore, a new benchmark
bm_iqp_circuit
, benchmarking mostly diagonal gates, was added and other benchmarks fixed.