Пример #1
0
def qrand(nbits):
    circ = QuantumCircuit(1, 1)
    circ.h(0)
    circ.measure(0, 0)
    val = simulate(circ, shots=nbits, get='memory')
    b = ''
    for i in range(nbits):
        b += str(val[i])
    integ = int(b, 2)
    return integ
def propagate_statevector(vec, qc):
    """
    Take an initial statevector 'vec', initialize
    a circuit with this statevector, execute the
    quantum circuit 'qc' on it and return the new
    statevector.
    """
    qc_i = QuantumCircuit(2, 0)
    qc_i.initialize(vec)

    return simulate(qc_i + qc, get='statevector')
def qrand(nbits):
    # generates nbits real random numbers using quantum state measurements in qiskit.
    circ = QuantumCircuit(1, 1)
    circ.h(0)
    circ.measure(0, 0)
    val = simulate(circ, shots=nbits, get='memory')
    b = ''
    for i in range(nbits):

        b += str(val[0])

    integ= int(b, 2)
    return integ
Пример #4
0
 def get_random_initial_state(self):
     qc = QuantumCircuit(2, 0)
     qc.data = [random.choice(list(self.gates.values())) for _ in range(self.length)]
     return simulate(qc, get='statevector')