def use_projectq_backends(): # ProjectQ simulator q_circuit = load_qasm_file('ghz.qasm') result = execute(q_circuit, backend=QasmSimulatorProjectQ(), shots=100).result() print("counts: ") print(result.get_counts(q_circuit)) # ProjectQ statevector simulator q_circuit = load_qasm_file('simple.qasm') result = execute(q_circuit, backend=StatevectorSimulatorProjectQ()).result() print("final quantum amplitude vector: ") print(result.get_statevector(q_circuit))
def setup(self): version_parts = qiskit.__version__.split('.') if version_parts[0] == '0' and int(version_parts[1]) < 5: self.local_qasm_simulator = None elif hasattr(qiskit, 'BasicAer'): self.local_qasm_simulator = qiskit.BasicAer.get_backend( 'qasm_simulator') elif hasattr(qiskit, 'get_backend'): self.local_qasm_simulator = qiskit.get_backend( 'local_qasm_simulator') else: self.local_qasm_simulator = qiskit.BasicAer.get_backend( "qasm_simulator") self.has_compile = False if hasattr(qiskit, 'compile'): self.has_compile = True self.single_gate_circuit = self._build_single_gate_circuit() self.cx_circuit = self._build_cx_circuit() self.qasm_path = os.path.abspath( os.path.join(os.path.dirname(__file__), 'qasm')) large_qasm_path = os.path.join(self.qasm_path, 'test_eoh_qasm.qasm') if hasattr(qiskit, 'load_qasm_file'): self.large_qasm = qiskit.load_qasm_file(large_qasm_path) elif version_parts[0] == '0' and int(version_parts[1]) < 5: self.large_qasm = qiskit.QuantumProgram() self.large_qasm.load_qasm_file(large_qasm_path, name='large_qasm') else: self.large_qasm = qiskit.QuantumCircuit.from_qasm_file( large_qasm_path)
def use_jku_backend(): q_circuit = load_qasm_file(RUNDIR + '/ghz.qasm') result = execute(q_circuit, backend='local_statevector_simulator_jku', shots=100).result() print("counts: ") print(result.get_counts(q_circuit))
def main(): args = options() circuit = load_qasm_file(args.qasm, name=args.qasm) qobj = compile(circuit, backend=args.backend, shots=args.shots) with open(args.qobj, 'w') as outfile: json.dump(qobj, outfile, indent=2, sort_keys=True, default=support_npint) if args.out_qasm: with open(args.out_qasm, 'w') as outfile: outfile.write(qobj['circuits'][0]['compiled_circuit_qasm'])
def use_sympy_backends(): """ Usage examples for the Sympy simulators """ # register with the SympyProvider to get access to its simulators register(provider_class=SympyProvider) q_circuit = load_qasm_file('simple.qasm') # sympy statevector simulator result = execute(q_circuit, backend='sympy_statevector_simulator').result() print("final quantum amplitude vector: ") print(result.get_statevector(q_circuit)) # sympy unitary simulator result = execute([q_circuit], backend='sympy_unitary_simulator').result() print("\nunitary matrix of the circuit: ") print(result.get_unitary(q_circuit))
def setUp(self): self.qasm_filename = self._get_resource_path('simple.qasm') self.q_circuit = load_qasm_file(self.qasm_filename)
def setUp(self): wrapper.register(provider_class=SympyProvider) self.qasm_filename = self._get_resource_path('simple.qasm') self.q_circuit = load_qasm_file(self.qasm_filename)
import sys import qiskit as qi import matplotlib.pyplot as plt from qiskit.tools.visualization import circuit_drawer from qiskit import Aer import time #from qiskit import QuantumProgram #qp = QuantumProgram() prog = qi.load_qasm_file(sys.argv[1]) #circuit_drawer(prog).show() backend = Aer.get_backend('qasm_simulator') # Job is async job = qi.execute(prog, backend, shots=1) #The block below is not necessary #It is just way to make sure things are still running init_status = job.status() i = 0 while True: time.sleep(10) print(job.status(), i) i = i + 1 if init_status != job.status(): break #This call blocks waiting for the job completion #But it will always have completed (or crashed)