def random_bitstring_generator(bit_number, backend):
bitstring = ""
one_qubit_random_bit_generator_circuit = QuantumCircuit(4,4)
one_qubit_random_bit_generator_circuit.h(3)
one_qubit_random_bit_generator_circuit.measure(3,3)
for _ in range(bit_number):
counts = execute(one_qubit_random_bit_generator_circuit, backend, shots=8000).result().get_counts()
bit = list(counts.keys())[0]
bitstring += bit
return bitstring
from qiskit.providers.aer import QasmSimulator
provider = IBMQ.load_account()
ibmq_melbourne = provider.get_backend('ibmq_16_melbourne')
backend = QasmSimulator.from_backend(ibmq_melbourne)
print(random_bitstring_generator(512, backend))```
Using the above code,
I am only getting an output bit string with all 0's even with changing number of shots.
what is the error leading to incorrect output.
I am trying to generate a long random sequence
$\begingroup$
$\endgroup$
-
$\begingroup$ I am not able to achieve the results with the implementation given here. As also It gives errors which i am unable to rectify. like ERROR code 3444:login failed though i am logged in with gmail account in Q experience.I mistakenly regenerated the API token, should it have any effect on the error above as i logged out and logged in again too but the error still was the same.I am an open provider user in IBM Q experience $\endgroup$ – parth Dec 28 '20 at 4:57
$\begingroup$
$\endgroup$
How about:
def random_bitstring_generator(bit_number, backend):
bitstring = ""
one_qubit_random_bit_generator_circuit = QuantumCircuit(1, 1)
one_qubit_random_bit_generator_circuit.h(0)
one_qubit_random_bit_generator_circuit.measure(0, 0)
for _ in range(bit_number):
counts = execute(one_qubit_random_bit_generator_circuit, backend, shots=1).result().get_counts()
bit = list(counts.keys())[0]
bitstring += bit
return bitstring
backend = BasicAer.get_backend('qasm_simulator')
random_bitstring_length = 100
print(random_bitstring_generator(random_bitstring_length, backend) )
This would output something like:
0000010000010010001000111010001110001000000100110011110110101010111011001100100001100100001101100000
Note that the number of shot is 1 since we just creating some random number and not finding the probability of seeing $|0\rangle$ and $|1\rangle$.
-
$\begingroup$ does this mean that i should be trying to execute with minimum number of qubits because when i am executing the above code for 3,4 or more qubits the sequence doesn't appear to be random as large number of continuous 0s and 1s appear inside the sequence.Also when i am trying to execute over any prototype like vigo,santiago or ourense it outputs error code 3446:login failed though i am logged in IBM Q Experience with gmail account. I am only using quantum lab /Q Experience GUI and do not know much of python for Qiskit. $\endgroup$ – parth Dec 28 '20 at 4:49