create a circuit of 5 qubits
qr = QuantumRegister(5, "qr") # quantum bit register
cr = ClassicalRegister(5, "cr") # classical bit register
circuit = QuantumCircuit(qr, cr)
# all qubits in superposition (50%:50% chance to be in |0> or |1>) and independent of each other
#The circuit is a superposition of 5 qubits.
circuit.h(qr)
circuit.h(qr)
circuit.h(qr)
circuit.h(qr)
circuit.h(qr)
circuit.h(qr)
circuit.measure(qr, cr)
circuit.draw(output='mpl', scale=1)
backend = Aer.get_backend('qasm_simulator')
result = execute(circuit, backend, shots=128, memory=True).result()
# get all experiments (number of shots)
rawvalues_sim = result.get_memory()
print(rawvalues_sim)
counts = result.get_counts()
print(counts)
plot_histogram(counts)
print("Length of data:", len(rawvalues_sim))
binarybytes = []
combinedbytes=[]
mainstring = 0
# for each qubit
for round in range(0, 5):
# construct sequence of 0s & 1s, creating a Byte for each sequence of 8 bits
rawvalues_sim_str = "".join(rawvalues_sim)
startindex = 0
endindex = 128
for i in range(0, len(rawvalues_sim_str),128): #rawvalues is storing 5 bits per index
b=rawvalues_sim_str[startindex:endindex]
startindex = endindex
endindex += 128
print(b)`
the b
here prints the random 128 sequence of bits. Now I want to find the identical bits in sequence of 128 bits. But I don't understand how.
Aucun commentaire:
Enregistrer un commentaire