<jupyter_start><jupyter_text>Getting started with IonQ and JSON on Azure QuantumThis notebook shows how to send a basic quantum circuit expressed using the [IonQ JSON spec](https://docs.ionq.com/tag/quantum_programs) to a Honeywell target via the Azure Quantum service. First, install `azure-quantum` and optionally `matplotlib` for plotting:<jupyter_code># To install the Azure Quantum client package, uncomment and run the line below:
#
# !pip install azure-quantum==0.19.2109.165653 --quiet
#
# We also recommend installing matplotlib, if you don't have it installed already:
# !pip install matplotlib --quiet<jupyter_output><empty_output><jupyter_text>Connecting to the Azure Quantum serviceTo connect to the Azure Quantum service, find the resource ID and location of your Workspace from the Azure portal here: https://portal.azure.com. Navigate to your Azure Quantum workspace and copy the values from the header.<jupyter_code>from azure.quantum import Workspace
from azure.quantum.target import IonQ

# Enter your workspace details here
# Find your resource ID and location via portal.azure.com
workspace = Workspace(
    resource_id="",
    location=""
)<jupyter_output><empty_output><jupyter_text>Use `workspace.get_targets` to see what targets are currently available for the Honeywell provider, including wait times. Running this method will trigger authentication to your Microsoft account, if you're not already logged in.<jupyter_code>workspace.get_targets(provider_id="ionq")
# See https://docs.ionq.com/#tag/quantum_programs for JSON format spec
circuit = {
    "qubits": 3,
    "circuit": [
        {
        "gate": "h",
        "target": 0
        },
        {
        "gate": "cnot",
        "control": 0,
        "target": 1
        },
        {
        "gate": "cnot",
        "control": 0,
        "target": 2
        },
    ]
}<jupyter_output><empty_output><jupyter_text>Run on IonQ Simulator Submit the circuit to the IonQ Simulator target. The following example uses the IonQ simulator, which returns a Job object. For more information, see [Azure Quantum Job](https://review.docs.microsoft.com/en-us/azure/quantum/optimization-job-reference).<jupyter_code>target = IonQ(workspace=workspace, name="ionq.simulator")
job = target.submit(circuit)
job.id<jupyter_output><empty_output><jupyter_text>Wait until the job is complete and then fetch the results.<jupyter_code>results = job.get_results()
results<jupyter_output>....<jupyter_text>You can then visualize the results using [Matplotlib](https://matplotlib.org/stable/users/installing.html).<jupyter_code>%matplotlib inline
import pylab as pl
pl.rcParams["font.size"] = 16
# The histogram returned by the results can be sparse, so here we add any of the missing bitstring labels.
hist = {format(n, "03b"): 0 for n in range(8)}
hist.update({format(int(k), "03b"): v for k, v in results["histogram"].items()})
pl.bar(hist.keys(), hist.values())
pl.ylabel("Probabilities")<jupyter_output><empty_output><jupyter_text>Run on IonQ QPU Note: The time required to run a circuit on the QPU may vary depending on current queue times. Submit the circuit to the IonQ QPU target.<jupyter_code>qpu_target = IonQ(workspace=workspace, name="ionq.qpu")
qpu_job = qpu_target.submit(circuit)
qpu_job.id<jupyter_output><empty_output><jupyter_text>Wait until the job is complete and then fetch the results.<jupyter_code>results = qpu_job.get_results()
results<jupyter_output><empty_output><jupyter_text>Plot the results.<jupyter_code>pl.rcParams["font.size"] = 16
hist = {format(n, "03b"): 0 for n in range(8)}
hist.update({format(int(k), "03b"): v for k, v in results["histogram"].items()})
pl.bar(hist.keys(), hist.values())
pl.ylabel("Probabilities")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11018989034501203, 'fraction_numerical': 0.009360791655522867, 'mean_word_length': 5.032258064516129, 'pattern_counts': {'":': 10, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '84617', 'license': 'MIT', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1150, 'n_words': 363, 'path': 'samples/getting-started/azure-quantum/provider-specific/Getting-started-with-IonQ-and-JSON-on-Azure-Quantum.ipynb', 'repo_name': 'ltalirz/Quantum', 'size': '3739'}