Skip to content

Instantly share code, notes, and snippets.

@leachy14
Created August 5, 2017 00:34
Show Gist options
  • Save leachy14/d8ba7f80626373a7dc4810c08b6a4076 to your computer and use it in GitHub Desktop.
Save leachy14/d8ba7f80626373a7dc4810c08b6a4076 to your computer and use it in GitHub Desktop.
This is a simple quantum program that will put qubit 0 in an exited state and then superposition
import sys
sys.path.append('.../..../') # solve the relative dependencies if you clone QISKit from the Git repo and use like a global.
from qiskit import QuantumProgram
import Qconfig
Q_SPECS = { #quantum specs 4 qubits 4 cregisters
'circuits': [{
'name': 'Circuit',
'quantum_registers': [{
'name': 'qr',
'size': 4
}],
'classical_registers': [{
'name': 'cr',
'size': 4
}]}],
}
qp = QuantumProgram(specs=Q_SPECS) #declare program
# get the circuit by Name
circuit = qp.get_circuit('Circuit')
# get the Quantum Register by Name
quantum_r = qp.get_quantum_register('qr')
# get the Classical Register by Name
classical_r = qp.get_classical_register('cr')
circuit.x(quantum_r[0])
circuit.h(quantum_r[0])
circuit.measure(quantum_r[0], classical_r[0])
#circuit should produce 0 50 1 50
backend = 'ibmqx2' # Backend where you execute your program; in this case, on the Real Quantum Chip online
circuits = ['Circuit'] # Group of circuits to execute
shots = 1024 # Number of shots to run the program (experiment); maximum is 8192 shots.
max_credits = 3 # Maximum number of credits to spend on executions.
qp.set_api(Qconfig.APItoken, Qconfig.config['url']) # set the APIToken and API url
result_real = qp.execute(circuits, backend, shots=shots, max_credits=3, wait=10, timeout=240, silent=False)
print(result_real.get_counts('Circuit'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment