from qiskit_ibm_runtime import IBMRuntimeService

# Option 1 - Save default accounts per channel
IBMRuntimeService.save_account(channel="ibm_quantum", token="<IBM Quantum API token>")
IBMRuntimeService.save_account(
    channel="ibm_cloud",
    token="<IBM Cloud API key>",
    instance="<CRN> or <Service Instance Name>",
)

# Option 2 - Save account by name
IBMRuntimeService.save_account(name="backup-account", channel="ibm_quantum", token="<IBM Quantum API token>")

IBMRuntimeService.saved_accounts()

IBMRuntimeService.delete_account(name="backup-account")

# Option 1 - Based on saved default accounts per channel
service = IBMRuntimeService(channel="ibm_quantum")
service = IBMRuntimeService(channel="ibm_cloud")

# Option 2 - Based on saved named account
service = IBMRuntimeService(name="backup-account")

# Option 3 - By passing account credentials
service = IBMRuntimeService(channel="ibm_quantum", token="<IBM Quantum API token>")
service = IBMRuntimeService(channel="ibm_cloud", token="<IBM Cloud API key>", instance="<CRN> or <Service Instance Name>")

# Option 4 - By reading from environment variables 
service = IBMRuntimeService() # requires environment configuration via QISKIT_IBM_TOKEN, QISKIT_IBM_URL, QISKIT_IBM_INSTANCE

service.pprint_programs()

service.programs()

program = service.program("sampler")
print(program)

service.backends()

service.backends(operational=True, min_num_qubits=64)

service.least_busy()

from qiskit import QuantumCircuit

bell = QuantumCircuit(2)
bell.h(0)
bell.cx(0, 1)
bell.measure_all()

bell.draw()

# Specify the program inputs here.
program_inputs = {
    "circuits": bell,
    "circuit_indices": [0],
}

job = service.run(
    program_id="sampler",
    inputs=program_inputs,
)

# Printing the job ID in case we need to retrieve it later.
print(f"Job ID: {job.job_id}")

# Get the job result - this is blocking and control may not return immediately.
result = job.result()
print(result)
# see which backend the job was executed on
print(job.backend)

backend = service.backend("ibmq_qasm_simulator")
backend

backend.name

backend.num_qubits

backend.max_circuits

backend.basis_gates