Skip to content

Commit

Permalink
Use numpy randint instead of choice for conditional (Qiskit#3248)
Browse files Browse the repository at this point in the history
The conditional code in qiskit.circuit.random.random_circuit() was
creating a list of 2^n_qubits to use np.random.choice() to pick a
single integer from that list. However, when you have a large number of
qubits, like 53, this will result in a memory error because you're
trying to allocate a list larger than is possible. This commit changes
the selection of the conditional value to select a random integer
directly instead of using a list to select a random integer.
  • Loading branch information
mtreinish authored and kdk committed Oct 11, 2019
1 parent b1e2595 commit 195f232
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions qiskit/circuit/random/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def random_circuit(n_qubits, depth, max_operands=3, measure=False,

# with some low probability, condition on classical bit values
if conditional and rng.choice(range(10)) == 0:
possible_values = range(pow(2, n_qubits))
value = rng.choice(list(possible_values))
value = rng.randint(0, np.power(2, n_qubits))
op.condition = (cr, value)

qc.append(op, register_operands)
Expand Down

0 comments on commit 195f232

Please sign in to comment.