import sys
import warnings

if not sys.warnoptions:
    warnings.simplefilter("ignore")

import qiskit.tools.jupyter

%qiskit_version_table

hub = 'ibm-q-community'
group = 'ieee-session'
project = 'event-2021'
backend_name = 'ibm_perth'

import qiskit
from qiskit import IBMQ
from qiskit.providers.ibmq.exceptions import IBMQAccountCredentialsNotFound

#IBMQ.save_account("<token>")
try:
    IBMQ.load_account()
except IBMQAccountCredentialsNotFound:
    print("Could not find your credentials"
          "Uncomment the lines above and insert your API token "
          "which can be found here https://quantum-computing.ibm.com/account."
          "After saving your credentials add back the comment."
         )
    raise

from qiskit.providers.ibmq.exceptions import IBMQProviderError

# load provider
try:
    provider = IBMQ.get_provider(hub=hub, group=group, project=project)
except IBMQProviderError:
    print(
        "The provider was not found. "
        "This means your IBM Quantum Services account was not yet added. "
        "Contact one of the tutorial presenters to add you."
    )
    raise
    
# Get our backend
backend = provider.get_backend(backend_name)

qubit = 0

from qiskit import QuantumCircuit

h_qc = QuantumCircuit(1, 1, name="|+> Prep")
h_qc.h(0)
h_qc.measure(0, 0)
h_qc.draw(idle_wires=False)

from qiskit import transpile

h_qc_transpiled = transpile(h_qc, backend, initial_layout=[1])
h_qc_transpiled.draw(idle_wires=False)

job = backend.run(h_qc_transpiled)
print(f"Your job's id: {job.job_id()}")
result = job.result()
print(f"|+> preparation results: {result.get_counts(0)}")

job.error_message()

from run_openqasm3 import run_openqasm3
job = run_openqasm3(h_qc_transpiled, backend)

