qiboteam / qibojit-benchmarks

Benchmark code for qibojit performance accessment
Apache License 2.0
2 stars 3 forks source link

Add fusion max_qubits option in compare.py #17

Closed stavros11 closed 2 years ago

stavros11 commented 2 years ago

Adds a --max-qubits option in compare.py which allows controlling the maximum number of qubits used in fusion optimization for the relevant backends. In this branch only qibo and qiskit support fusion but we should fix this for all libraries that provide fusion optimization, such as qulacs, qsim and HybridQ (will open another PR for that one).

@mlazzarin this may be helpful for your qsim benchmarks in #14, let me know if I should change something. I am using it to benchmark some fusion approaches for qibo (qiboteam/qibo#505) and also to compare qiskit and HybridQ fusion.

NOTE: We should keep in mind that qiskit has a lower threshold for applying fusion which is set to 14 by default and we do not change it here. This means that fusion won't be applied if the circuit has less than 14 qubits.

EDIT: CI is failing because the released qibo supports only two-qubit fusion.

mlazzarin commented 2 years ago

Thanks, I'll integrate this feature in #14. Short question: what is the expected behavior for max_qubits = 1? Because in this PR it looks like fusion is completely disabled, but an user may expect the fusion of one-qubit gates, when possible.

NOTE: We should keep in mind that qiskit has a lower threshold for applying fusion which is set to 14 by default and we do not change it here. This means that fusion won't be applied if the circuit has less than 14 qubits.

Shall we add an error if max_qubits > 0 and nqubits <= 14, to not forget it?

stavros11 commented 2 years ago

Thanks, I'll integrate this feature in #14. Short question: what is the expected behavior for max_qubits = 1? Because in this PR it looks like fusion is completely disabled, but an user may expect the fusion of one-qubit gates, when possible.

Good point, I fixed this so that fusion is disabled when max_qubits <= 0. For max_qubits = 1 the behavior will depend on the library.

Shall we add an error if max_qubits > 0 and nqubits <= 14, to not forget it?

I changed the code here to manually set the threshold to 1 to make sure that fusion always happens if max_qubits > 0. I believe this is better in order to have a uniform behavior across all libraries, we should just make sure that every library that supports fusion does not have any hidden thresholds that disable it.

stavros11 commented 2 years ago

I added a --library-options flag in the benchmark script which allows passing arbitrary option arguments to the backends. These options can be the max_qubits for fusion or other library dependent arguments, such as the number of threads for qiskit and qsim or flags for enabling the circuit optimization/simplification for Qulacs or HybridQ. For example:

python compare.py --nqubits 20 --library qiskit --library-options max_qubits=4,max_parallel_threads=16

would run qiskit using fusion up to four qubit gates and 16 CPU threads.

@mlazzarin @andrea-pasquale please have a look and let me know if you agree with this layout.