def test_apis(): qbits = Qbits(4) # Qbit # id # name # Implements iterable, so we get all of the nice # python indexing functionality # even = qbits[::2] # Get the even indexed qbits # odd = qbits[1::2] # Get the odd indexed qbits # TODO: Support multiple qbits, and this test. # TODO: Add empty circuit test # TODO: Infer qbits used from ciruit rather than from Qbits layer # H(even) does not work. qc = QuantumCircuit() qc += Qbits(1) # qc += H(even) # qc += X(odd) qc += H(0) qc.add(Measure([qbits])) job = qc.run(100) result = job.result assert result["1111"] == 0 # Any single qbit should accept # A single qbit H(qbits[1])
def simple_circuit(): qc = QC() qc.add(Qbits(3)) qc.add(H(1)) qc.add(CNOT(1, 0)) qc.add(Measure([0, 1])) return qc
def test_modulus_circuit(): circuit = Circuit() circuit.add(Qbits(5)) circuit.add(quantum_amod_15(4)) circuit.add(Measure([0, 1])) job = circuit.run(1024) result = job.result print(result)
def test_circuit_on_simulator(self): qc = QC() qc.add(Qbits(3)) qc.add(H(1)) qc.add(CNOT(1, 0)) qc.add(Measure([0, 1])) ibm_provider = IBMQ() job = qc.run(1024, ibm_provider) result = job.result counts = result.counts assert counts[0] > 450 < counts[3]
def test_iterable(): qbits = Qbits(5) # Implements iterable, so we get all of the nice # python indexing functionality even = qbits[::2] # Get the even indexed qbits odd = qbits[1::2] # Get the odd indexed qbits assert len(even) == 3 assert len(odd) == 2 assert even == [0, 2, 4] assert odd == [1, 3]
def test_simons(): qbits = Qbits(6) # Q = QuantumCircuit(qbits) # Doesn't work, not implemented Q = QuantumCircuit().add(qbits) Q.add(H(0)).add(H(1)).add(H(2)) Q.add(CNOT(0, 3)).add(CNOT(1, 4)).add(CNOT(2, 5)) Q.add(CNOT(1, 4)).add(CNOT(1, 5)) Q.add(H(0)).add(H(1)).add(H(2)) Q.add(Measure(qbits[:3])) # Doesn't work, partial measurements... job = Q.run(1000, provider=QiskitProvider()) result = job.result print(result)
def test_QFT(): qbits = Qbits(4) X = Circuit() X.add(qbits) X.add(H(0)).add(H(1)).add(H(2)).add(H(3)) X.add(QFT(0, 1, 2, 3)) X.add(Measure([0, 1, 2, 3])) # # qc2 = QuantumCircuit() + H(qbits[0]) + X(qbits[1]) # # qbits = Qbits(4) # qc = H(qbits) * QFT(qbits) # # qc += QFT(qbits[0:3]) # qc += qc2 # # qc.add(H()) # # qc = H(qc[0:3]) # qc = Z(qc[1]) # # qbits = Qbits(4) # cbits = Cbits(4) # # qc = QuantumCircuit(qbits=qbits, cbits=cbits) # -> err # qc += Hadamard(qbits[0]) + Z(qbits[1]) # # qc.add(Measure([qbits[0]])) # qc += Measure(qbits[0]) # # qc.add(Measure(qbits), name='Output') # X = Circuit(qbits) # X = H(X) # Y = Z(X) # A = H(X) # # qbits = Qbits(4) # X = Circuit() + qbits + H(qbits) + QFT(qbits) + Measure(qbits) # # Y = X.run(QuantumSimulator, times=100) job = X.run(1024) result = job.result assert result
def test_qsession_run(): from shor.backends import QSession sess = QSession() from shor.quantum import Circuit sess.run(Circuit().add(Qbits(1)).add(H()), num_shots=10)