def test_matplotlib_drawer(self): filename = self._get_resource_path('current_matplot.png') qc = self.sample_circuit() matplotlib_circuit_drawer(qc, filename=filename) self.assertImagesAreEqual(filename, self.matplotlib_reference) os.remove(filename)
import qiskit from PIL import Image from qiskit.tools.visualization import matplotlib_circuit_drawer qr = qiskit.QuantumRegister(1) cr = qiskit.ClassicalRegister(1) program = qiskit.QuantumCircuit(qr, cr) program.measure(qr, cr) image = matplotlib_circuit_drawer(program) Image._show(image)
qc.x(q[13]) # measure for j in range(16): qc.measure(q[j], c[j]) qiskit.IBMQ.load_accounts() backend = qiskit.IBMQ.get_backend('ibmq_qasm_simulator') print("We'll use the least busy device:", backend.name()) shots = 64 job = qiskit.execute(qc, backend, shots=shots) stats = job.result().get_counts() print(stats) image = matplotlib_circuit_drawer(qc) plot_histogram(stats) import matplotlib.pyplot as plt plt.rc('font', family='monospace') def plot_smiley(stats, shots): for bitString in stats: char = chr( int(bitString[0:8], 2) ) # get string of the leftmost 8 bits and convert to an ASCII character char += chr( int(bitString[8:16], 2)
import qiskit from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute from qiskit.backends.jobstatus import JOB_FINAL_STATES from qiskit.tools.visualization import plot_histogram, circuit_drawer, matplotlib_circuit_drawer q = QuantumRegister(2) c = ClassicalRegister(2) qc = QuantumCircuit(q, c) # entanglement: qc.h(q[0]) qc.cx(q[0], q[1]) qc.measure(q, c) qiskit.IBMQ.load_accounts() backend = qiskit.IBMQ.get_backend('ibmq_qasm_simulator') job_exp = execute(qc, backend=backend, shots=1024, max_credits=3) print("Job ID %s" % job_exp.job_id()) while job_exp.status() not in JOB_FINAL_STATES: print(job_exp.status()) sleep(1) print(job_exp.status()) matplotlib_circuit_drawer(qc) plot_histogram(job_exp.result().get_counts(qc)) print('We made entanglement of two qubits!')