from qiskit import (
    QuantumCircuit,
    QuantumRegister,
    ClassicalRegister,
    execute
)
from qiskit_rigetti import RigettiQCSProvider

provider = RigettiQCSProvider()
backend = provider.get_simulator(num_qubits=2, noisy=True)  # or provider.get_backend(name="Aspen-9") when running via QCS

circuit = QuantumCircuit(QuantumRegister(2, "q"), ClassicalRegister(2, "ro"))
circuit.h(0)
circuit.cx(0, 1)
circuit.measure([0, 1], [0, 1])

circuit.draw()

job = execute(circuit, backend, shots=1000)
result = job.result()
counts = result.get_counts()
print("Counts for experiment:", counts)

from qiskit.tools.visualization import plot_histogram

plot_histogram(counts)