From 195f2328efd831958d1eb9f622f9c49e7608b231 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Fri, 11 Oct 2019 16:36:46 -0400 Subject: [PATCH] Use numpy randint instead of choice for conditional (#3248) 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. --- qiskit/circuit/random/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/qiskit/circuit/random/utils.py b/qiskit/circuit/random/utils.py index 21e9737e1f39..a464fbb8d1b3 100644 --- a/qiskit/circuit/random/utils.py +++ b/qiskit/circuit/random/utils.py @@ -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)