-
Notifications
You must be signed in to change notification settings - Fork 39
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
Gate benchmarking CI #87
Conversation
Codecov Report
@@ Coverage Diff @@
## master #87 +/- ##
=======================================
Coverage 98.03% 98.03%
=======================================
Files 3 3
Lines 51 51
=======================================
Hits 50 50
Misses 1 1 Continue to review full report at Codecov.
|
This reverts commit 281bb33.
This reverts commit c55da67.
This reverts commit 0bf6558.
…-lightning into gate_bench_ci
Looks good! Some thoughts on what could be added/changed:
|
Thanks @ThomasLoke!
Isn't a reference to the numpy array being passed when calling the bound C++ function from Python? Sharing some further benchmarks: Benchmarking C++ Used the following source to call on #include "pennylane_lightning/src/Apply.hpp"
#include <iostream>
using std::vector;
using Pennylane::CplxType;
using Pennylane::StateVector;
int main(){
const int qubits = 23;
const int len = exp2(qubits);
vector<CplxType> vec(len);
// Prepare |00....0>
vec.at(0) = 1;
StateVector state(vec.data(), len);
apply(state, {"PauliX"},{{0}}, {{}}, qubits);
return 0;
} Created a flame graph for applying This seems to indicate that calling On a separate run locally, could confirm that the second use of So perhaps it could be worth considering if Benchmarking Python As a separate benchmark, profiled
18 qubits For 23 qubits,
18 qubits For 23 qubits, |
From my vague recollection, we were making a copy of the numpy array before applying operations and/or rotations to avoid the existing state being mutated? Or maybe the semantics have changed since I've last looked...
I'm not surprised, but I suspect this varies quite a bit depending on the gate type and dimensionality. A PauliX gate amounts to nothing more than swapping some memory locations, and has to generate That said, there's probably some things we can do to cut down the runtime of |
When applying the operations, the state is being passed by reference. Indeed, the state is being copied before applying the rotations. However, these benchmarks use |
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.
Thanks @antalszava, looks great! One general question - these benchmarks are good for comparisons with existing sources, but could we also consider a less trivial circuit? For example, we could even do a random circuit like in the comparison tests or something like strongly entangling layers. And potentially also a calculation of the derivative (although that could come when we add the adjoint). I'm also curious about whether this clashes with/complements the current benchmarking suite being developed 🤔
From my vague recollection, we were making a copy of the numpy array before applying operations and/or rotations to avoid the existing state being mutated? Or maybe the semantics have changed since I've last looked...
Yes, a copy occurs both on state preparation and measurements not in the standard basis. For state prep, if a user does qml.QubitStateVector
, we have a copy to prevent the user input state being mutated.
Average runtime (instead of total) + error bars for standard deviation.
I think it's already avg? (Or maybe it changed since the comment). Agree with std. dev. Also, maybe prefer lines passing through the dots.
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
# Acknowledghing the solution for plotting from the quantum-benchmarks repository |
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.
Also I'm curious, how much of this came directly from the external repo? It seems like simple matplotlib
plotting.
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.
Indeed, the plotting was based on the external repo. Wanted to specify some attribution as the plots would be similarly constructed and would look similar, maybe enough to just leave a mention?
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
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.
I was also wondering if this script is more suited to attribution, given that we are following the general approach of the external repo.
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.
Thanks! Moved the licensing into this file.
bbox_to_anchor=(0.5, 0.97), | ||
) | ||
|
||
plt.savefig("gates.png") |
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.
Minor thing for this PR, but I wonder if we could have something like the QML repo where the CI checks in a PR link directly to the artifact? Think it's in this workflow.
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.
That would be awesome, but after a look around it seems that there's no straightforward solution 😞 in the qml
repo we are using a CircleCI specific action
Ah, you're probably right. I assumed it was the total because the scale for time was 10^5-10^6, but I see now that its labelled as ns, i.e. nanoseconds. In which case, that isn't so surprising, and its fine then. |
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Thank you @trbromley and @ThomasLoke for the comments!
We could definitely, although this PR is just meant to add a couple of elementary benchmarks just to give a quick impression on how the performance is affected. Although having error bars would be great, it seems that using Would be tempted to leave this as is just because |
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.
Thanks @antalszava 💯
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Acknowledging the approach for plotting from the quantum-benchmarks repository |
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.
Actually, maybe if the code is taken exactly from that repo, we should include the licence here too (sorry!)
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 worries, thanks! Updated
Changes
Adds basic benchmarks that each simulate gate applications for qubits in the regime of
[1, 3, 5, 10, 15, 18]
. The"PauliX", "T", "Hadamard", "CNOT"
gates are run10000
times by timing the following snippet:The output is a plot comparing:
lightning.qubit
according to the modifications in the PR where the CI check is runlightning.qubit
inmaster
default.qubit
Output: a
.png
image with size ~40 KB that is uploaded as an artifact after each run.Time to complete: around 3-4 minutes.
The check is run for each commit pushed to an open pull request.
The resulting image files are available in the list of checks by clicking on
Details
: