-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Speed up `random_circuit` There is no need to use the slower `append` (which adds a lot of checking overhead for large circuits) since we fully control the construction of the circuit. This also overhauls all the randomisation components to produce all the necessary randomness for a given layer in a single go. This massively reduces the Python-space and Numpy-dispatch overhead of the nested loop. The changes to the randomisation in this new form mean that on average, more gates will be generated per circuit, because the output will choose 1q gates more frequently than it chooses 2q, which in turn will be more frequent than 3q, but each layer of the "depth" still has to involve every qubit. The change is because the likelihood of choosing a gate with a given number of qubits is now proportional to how many different gates of that number of qubits there are in the options. For sample timings, the call `random_circuit(433, 1000, seed=1)` went from 15.2s on my machine (macOS Python 3.10, Intel i7 @ 2.3 GHz) down to 2.3s, so a speed-up of about 6-7x. * Add test of large-circuit condition generation * Use all gates in the standard library This deliberately does not use the `get_standard_gate_name_mapping` function, in order to avoid changes to that function breaking RNG compatibility in this unrelated function. * Fix docstring * Add comments on algorithm Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0d48974
commit 351da44
Showing
3 changed files
with
166 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
releasenotes/notes/speedup-random-circuits-8d3b724cce1faaad.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
features: | ||
- | | ||
Random-circuit generation with ``qiskit.circuit.random.random_circuit`` is | ||
now significantly faster for large circuits. | ||
- Random-circuit generation with ``qiskit.circuit.random.random_circuit`` will | ||
now output all "standard" gates in Qiskit's circuit library (:mod:`.circuit.library`). | ||
This includes two 4-qubit gates :class:`.C3SXGate` and :class:`.RC3XGate`, and the | ||
allowed values of ``max_operands`` have been expanded accordingly. | ||
upgrade: | ||
- | | ||
The exact circuit returned by ``qiskit.circuit.random.random_circuit`` for a | ||
given seed has changed. This is due to efficiency improvements in the | ||
internal random-number generation for the function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters