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

Benchmarking #71

Merged
merged 14 commits into from
Mar 22, 2019
Merged

Benchmarking #71

merged 14 commits into from
Mar 22, 2019

Conversation

atilag
Copy link
Member

@atilag atilag commented Feb 28, 2019

Summary

Introduce benchmarking system to detect possible regressions.

Details and comments

Performance is one the goals of our simulators, and the only way to ensure our simulators run at their highest speed is by tracking how they perform over time, so if any change causes a degradation in the performance, we need to know and act accordingly.
ASV (Airspeed Velocity) is a Pyhton framework for creating benchmarks, and is the one being used here to track our performance history, and warn us if we introduce a regression.
For now, all the benchmarks will run the QasmSimualtor, with three different noise models:

  • Ideal (no noise)
  • Kraus
  • Mixed Unitary
  • Reset
    And the benchmarks are:
  • Quantum Volume with 16 qubits and a circuit depth of 10
  • Simple circuit with only u3 gates but with different number of qubits: 5, 10 and 15 qubits each.
  • Simple circuit with only cnot gates but with different number of qubits: 5, 10 and 15 qubits each.

For the new benchmarks introduced by this PR, I haven't set any specific configuration for our threading strategy, so basically I'm delegating the concurrency to the heuristics we already have in place in the simulators.

These are the commands sequence to run the benchmarks and show the results:

  • Run all the benchmarks
$ asv run
  • Create results in html format
$ asv publish
  • Show the results as a preview
$ asv preview

As a first attempt, we will only monitor for time measurements (how much time takes a circuit to run) and only when the simulator starts executing the circuit. Initial setup and circuit compilation through Terra won't be measured (as this will be measured in the Qiskit metapackage).

Important!, I'm leaving the setting up of the workflow for publishing results to another Pull Request, this is all about having the scaffolding and a minor set of benchmarks in place.

TODO

  • Tune circuits (adding more, removing some, changing others)

@atilag atilag requested a review from chriseclectic February 28, 2019 14:23
pass


def time_ideal_quantum_volume(self, qobj):
Copy link
Member

Choose a reason for hiding this comment

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

I don't see where the qobj get passed into these functions being called?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, ASV calls it automatically.
It uses self.params as a way to specify the parameters of the functions that is going to benchmark, so in this case, you'll see in the constructor that there's a:

...
self.params = (self.qv_circuits)

So the qv_circuits are a list of qobjs that are going to be passed as function parameters

Copy link
Member

@chriseclectic chriseclectic Mar 19, 2019

Choose a reason for hiding this comment

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

Could you add a comment documenting that in TestSuite class/baseclass doc string?

mixed_unitary_noise_model, reset_noise_model, \
kraus_noise_model

class SimpleU3TimeSuite:
Copy link
Member

Choose a reason for hiding this comment

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

Could these *TimeSuite classes all inherit from a base class, since most of the code is the same other than the init method.

Copy link
Member Author

Choose a reason for hiding this comment

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

After talking to you about this, I'm gonna use self.params to add the noise model as a new parameter, so we only need one function.

)
self.params = (self.circuits)

def time_ideal_simple_u3(self, qobj):
Copy link
Member

Choose a reason for hiding this comment

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

Don't think _u3 is supposed to be here

Copy link
Member Author

Choose a reason for hiding this comment

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

Where would you put it?

Copy link
Member

Choose a reason for hiding this comment

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

This one is testing CX not u3

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! you are right... copy / pasting side effects :)

"""
qr = QuantumRegister(num_qubits)
circuit = QuantumCircuit(qr)
for i in range(num_qubits):
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to time a single u3 gate vs qubit number, and average over which qubit in circuit is applied to.

I.e: Estimate time t[j] of applying circuit.u3(qr[j]), and then compute t_ave = mean(t) and then plot t_ave vs total number of qubits in the circuit.

This should also be done for cx (averaged overall pairs of qubits) reset and measure (averaged over single qubits), and later we could add other specialized gates that have an optimised implementation.

This would allow estimating the single-shot run-time as if we know for n-qubits what t_ave_u3, t_ave_cx, t_ave_reset, t_ave_measure we can just multiply them by the number of instructions of each type in the circuit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok!
Let's move this to a follow up PR :)

atilag added 3 commits March 21, 2019 13:34
  noise models as parameters
* Minor style changes I've found
* Better docstring documentation
* Improving ASV virutal environments generation
@@ -98,7 +98,7 @@ std::ostream &operator<<(std::ostream &out, const std::array<T, N> &v) {

// ostream overload for maps
template <typename T1, typename T2, typename T3>
std::ostream &operator<<(std::ostream &out, const std::map<T1, T2, T3> &m) {
std::ostream &operator<<(std::oscmatrixeam &out, const std::map<T1, T2, T3> &m) {
Copy link
Member

Choose a reason for hiding this comment

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

Some typo going on here

Copy link
Member Author

Choose a reason for hiding this comment

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

XD

@atilag atilag changed the title [WIP] Benchmarking Benchmarking Mar 22, 2019
@atilag
Copy link
Member Author

atilag commented Mar 22, 2019

Ok, we are creating a follow-up PR with the changes propose by @chriseclectic about the new benchmarks, and I'm gonna merge this as everything is green now :)

@atilag
Copy link
Member Author

atilag commented Mar 22, 2019

Ups, I don't have review approval yet. @chriseclectic did I leave something out?

@chriseclectic chriseclectic merged commit b509b48 into Qiskit:master Mar 22, 2019
dcmckayibm pushed a commit to dcmckayibm/qiskit-aer that referenced this pull request Nov 3, 2019
* * Adding ASV as the framework for benchmarking

* Migratind old benchmark infra to ASV

* * Adding tools for benchmarks

* * Adding params to the benchmarks

* * Added new benchmarks for simple circuits with just u3 and cnots
  but different number of qubits

* * Simplifying to just one function to benchmark, by moving the
  noise models as parameters
* Minor style changes I've found

* * Simplifying benchmark code by moving the noise models to params
* Better docstring documentation
* Improving ASV virutal environments generation
@atilag atilag deleted the benchmarking branch June 1, 2020 14:24
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.

2 participants