### Basic Qiskit Script Setup Source: https://docs.ionq.com/guides/sdks/qiskit A minimal Python script to get started with Qiskit and IonQ. This example assumes the IonQProvider is initialized and ready for use. ```python from qiskit import QuantumCircuit # Create a quantum circuit with 2 qubits and 2 classical bits qc = QuantumCircuit(2, 2) ``` -------------------------------- ### Initialize IonQProvider and List Backends Source: https://docs.ionq.com/llms-full.txt Initialize the IonQProvider without arguments, assuming Qiskit can find the API key automatically. Then, print the list of available backends. This script verifies successful installation and setup. ```python from qiskit_ionq import IonQProvider provider = IonQProvider() print(provider.backends()) ``` -------------------------------- ### Install Qiskit and IonQ Provider Source: https://docs.ionq.com/llms-full.txt Use this command to install the Qiskit SDK and the IonQ provider for accessing IonQ hardware. Ensure you have Python and pip installed. ```bash pip install qiskit qiskit-ionq ``` -------------------------------- ### Install IonQ SDK with all extras Source: https://docs.ionq.com/llms-full.txt Install the IonQ SDK including all optional dependencies for full functionality. This is a prerequisite for running hybrid workloads. ```bash pip install 'ionq[all]' ``` -------------------------------- ### Basic Example Source: https://docs.ionq.com/api-reference/v0.3/native-gates-api A simple example circuit demonstrating the use of native gates with the IonQ API. ```APIDOC ## Basic example Here’s a simple example circuit using native gates with the IonQ API. ```json { "name": "Hello native gates!", "shots": 100, "qiskit": { "gates": [ { "gate": "gpi", "phase": 0.5, "target": 0 }, { "gate": "gpi2", "phase": 0.25, "target": 1 }, { "gate": "ms", "phases": [0.1, 0.2], "targets": [0, 1] }, { "gate": "zz", "angle": 0.3, "targets": [0, 1] } ] } } ``` ``` -------------------------------- ### Example Output of get_devices() Source: https://docs.ionq.com/sdks/qbraid/index This is an example of the output you might expect when calling the get_devices() method, showing available quantum devices. ```python [ 'harmony', 'advantage.lite', 'advantage.startup' ] ``` -------------------------------- ### Set up IonQ Backend Source: https://docs.ionq.com/sdks/qiskit/native-gates-qiskit Example of setting up an IonQ backend, using a simulator for initial testing. ```python from qiskit_ionq import IonQProvider provider = IonQProvider("YOUR_API_KEY") backend = provider.get_backend("ionq_simulator") ``` -------------------------------- ### Import IonQProvider and Initialize Source: https://docs.ionq.com/sdks/qbraid/native-gates-qbraid Import the IonQProvider from qbraid.runtime and initialize it with your API key. Then, get a device, such as the simulator. ```python from qbraid.runtime import IonQProvider provider = IonQProvider( api_key="YOUR_API_KEY" ) device = provider.get_device("simulator") ``` -------------------------------- ### Qiskit example: Running a circuit without debiasing Source: https://docs.ionq.com/llms-full.txt This Qiskit example demonstrates how to submit a circuit to an IonQ backend with debiasing explicitly turned off. Ensure you have `qiskit-ionq` installed. ```python from qiskit import QuantumCircuit from qiskit_ionq import IonQProvider, ErrorMitigation provider = IonQProvider() qpu_backend = provider.get_backend("qpu.forte-1") # Create a basic Bell State circuit: qc = QuantumCircuit(2, name="Qiskit job without debiasing") qc.h(0) nc.cx(0, 1) nc.measure_all() # Submit the circuit to IonQ Forte: job = qpu_backend.run( qc, shots=1000, error_mitigation=ErrorMitigation.NO_DEBIASING ) ``` -------------------------------- ### Setting up IonQ Provider and Backend Source: https://docs.ionq.com/sdks/qiskit/native-gates-qiskit This code snippet demonstrates how to import the IonQProvider and retrieve a backend instance, specifically using the simulator for initial setup. ```python from qiskit_ionq import IonQProvider provider = IonQProvider() ionq_backend = provider.get_backend("simulator") ``` -------------------------------- ### Initialize Get Started Form Logic with JavaScript Source: https://ionq.com/get-access This JavaScript code initializes the logic for a multi-step 'Get Started' form. It manages step visibility, stores user selections, and handles form state. It requires specific HTML structure with elements like '.get-started-form-wrapper', '.get-started-steps-list', and elements with IDs like '#get-started-heading'. ```javascript (function() { var formRoot = document.querySelector('.get-started-form-wrapper'); if (!formRoot) return; var stepList = formRoot.querySelector('.get-started-steps-list'); if (!stepList) return; var steps = Array.from(stepList.querySelectorAll('.get-started-step')); var mainHeading = document.querySelector('#get-started-heading'); var thanksHeading = document.querySelector('#thanks-heading'); var recommended = document.querySelector('#recommended-solution'); var qStepIds = [ 'get_started_2_step', 'get_started_3_step', 'get_started_4_step', 'get_started_5_step', 'get_started_6_step', 'get_started_7_step' ]; var idToHash = { get_started_2_step: 'current-program', get_started_3_step: 'use-cases', get_started_4_step: 'expert-access', get_started_5_step: 'team-size', get_started_6_step: 'satisfaction', get_started_7_step: 'special-requirement' }; steps.forEach(function(s) { s.style.transition = 'none'; }); var selectedOptionByStep = {}; function saveSelectedRadio(stepId, radioId) { selectedOptionByStep[stepId] = radioId; } function getSelectedRadio(stepId) { return selectedOptionByStep[stepId] || null; } function clearAllQSelections() { Object.keys(selectedOptionByStep).forEach(function(k) { delete selectedOptionByStep[k]; }); qStepIds.forEach(function(stepId) { var stepEl = getStepById('#' + stepId); if (!stepEl) return; var qRadios = stepEl.querySelectorAll('input[type="radio"]'); qRadios.forEach(function(radio) { radio.checked = false; var fakeUI = radio.closest('.w-radio') && radio.closest('.w-radio').querySelector('.w-radio-input'); if (fakeUI) fakeUI.classList.remove('w--redirected-checked'); var wrap = radio.closest('.get-started-option-wrapper'); if (wrap) wrap.classList.remove('checked'); }); var hiddenInputId = stepId.replace('_step', ''); var hiddenInput = document.getElementById(hiddenInputId); if (hiddenInput) hiddenInput.value = ''; }); } function restoreSelectedRadio(stepElement) { var stepId = stepElement.id; var radioId = getSelectedRadio(stepId); if (!radioId) return; var radio = document.getElementById(radioId); if ``` -------------------------------- ### Initialize IonQ Provider and Simulator Backend Source: https://docs.ionq.com/guides/simulation-with-noise-models Set up the IonQProvider and retrieve the 'ionq_simulator' backend. This is the first step before creating and running quantum circuits. ```python from qiskit import QuantumCircuit from qiskit_ionq import IonQProvider provider = IonQProvider() simulator_backend = provider.get_backend("ionq_simulator") ``` -------------------------------- ### Cirq example: Creating a job without debiasing Source: https://docs.ionq.com/llms-full.txt This Cirq example demonstrates how to create and submit a job to an IonQ backend with debiasing explicitly turned off. Ensure you have `cirq-ionq` installed. ```python import cirq import cirq_ionq # Create a basic Bell State circuit: q0, q1 = cirq.LineQubit.range(2) circuit = cirq.Circuit( cirq.H(q0), cirq.CNOT(q0, q1), cirq.measure(q0, q1, key='x') ) service = cirq_ionq.Service() # Submit the circuit to IonQ Forte: result = service.create_job( circuit=circuit, repetitions=1000, target='qpu.forte-1', name="Cirq job without debiasing" error_mitigation={"debias": False} ) ``` -------------------------------- ### Constrain qiskit-ionq Version Source: https://docs.ionq.com/guides/sdks/qiskit Install qiskit-ionq with a version constraint, for example, to ensure it is less than version 1.0. Pip will automatically install a compatible Qiskit version if one is not present. ```shellscript pip install qiskit-ionq <1.0 ``` -------------------------------- ### Retrieve QPU Job Results Source: https://docs.ionq.com/llms-full.txt Once a QPU job is completed, its results can be retrieved and processed. This example shows how to get histogram data. ```python result = job.results().to_cirq_result() print(result.histogram(key='x')) ``` -------------------------------- ### Set up IonQ Provider and Backend Source: https://docs.ionq.com/guides/sdks/qiskit Initialize the IonQProvider and select a specific backend, such as 'qpu.forte-1'. This is the first step to interacting with IonQ hardware. ```python from qiskit_ionq import IonQProvider # Set up the IonQ provider and backend provider = IonQProvider() backend = provider.get_backend("qpu.forte-1") ``` -------------------------------- ### Build and Run a Native Gate Circuit with qBraid Source: https://docs.ionq.com/sdks/qbraid/native-gates-qbraid Demonstrates how to initialize the IonQProvider, get a device, define a QASM string with native gates, and run a job. Ensure you replace 'YOUR_API_KEY' with your actual API key. ```python from qbraid.runtime import IonQProvider provider = IonQProvider(api_key="YOUR_API_KEY") device = provider.get_device("simulator") qasm = """ OPENQASM 3.0; qubit[3] q; gpi(0.5) q[0]; gpi2(0) q[1]; ms(0,0.5) q[1], q[2]; """ job = device.run(qasm, shots=1000) ``` -------------------------------- ### Unauthorized Response Example Source: https://docs.ionq.com/llms-full.txt A '401 Unauthorized' response indicates an issue with API authentication. Refer to the Authorization section for correct setup. ```json { "statusCode": 401, "error": "Unauthorized Error", "message": "Invalid key provided. See https://docs.ionq.com/#authentication for details, or email support@ionq.co for help." } ``` -------------------------------- ### Setting up an IonQ Backend Source: https://docs.ionq.com/llms-full.txt This code initializes an IonQ backend, using a simulator for demonstration purposes, to which transpiled circuits can be submitted. ```python from qiskit_ionq import IonQProvider provider = IonQProvider() ionq_backend = provider.get_backend("simulator") ``` -------------------------------- ### Create a Quantum Circuit for Debiasing Source: https://docs.ionq.com/guides/error-mitigation-debiasing Constructs a simple Bell state circuit and submits it for execution with error mitigation enabled. This example demonstrates the basic setup for debiasing. ```python qc = QuantumCircuit("2", name="Qiskit job without debiasing") qc.h(0) qc.cx(0, 1) qc.measure_all() # Submit the circuit to IonQ Forte: job = qpu_backend.run( qc, shots=1000, error_mitigation=True ) ``` -------------------------------- ### Example Output of Available Backends Source: https://docs.ionq.com/llms-full.txt This is an example of the output you should expect when running the script to list available IonQ backends. It shows the simulator and QPU backends. ```bash [, ] ``` -------------------------------- ### Transpile and Run Circuit with Unsupported Operations Source: https://docs.ionq.com/sdks/qiskit/native-gates-qiskit This example demonstrates how to build a circuit with operations that might not be natively supported, then transpile it to the supported QIS gates for execution on an IonQ backend. Ensure you have the necessary Qiskit and qiskit-ionq libraries installed. ```python from qiskit import QuantumCircuit, transpile from qiskit.circuit.library import UnitaryGate from qiskit_ionq import IonQProvider ``` ```python # Set up an IonQ backend (gateset="qis" is the default) ``` -------------------------------- ### Install qBraid with IonQ Provider Source: https://docs.ionq.com/llms-full.txt Use this command to install the qBraid SDK along with the necessary extras for the IonQ provider. This is the primary method for setting up the environment for IonQ integration. ```bash pip install 'qbraid[ionq]' ``` -------------------------------- ### Install cirq-ionq Source: https://docs.ionq.com/llms-full.txt Install the `cirq-ionq` package using pip. This command also installs the core Cirq functionality. It is recommended to perform this installation within a virtual environment. ```bash pip install cirq-ionq ``` -------------------------------- ### Initialize IonQProvider and Get Backend Source: https://docs.ionq.com/sdks/qiskit/native-gates-qiskit Import and initialize the IonQProvider to access quantum backends. Use get_backend to specify the desired simulator. ```python from qiskit_ionq import IonQProvider provider = IonQProvider() ionq_backend = provider.get_backend("simulator") ``` -------------------------------- ### Build, Transpile, and Run with Native Gates Source: https://docs.ionq.com/sdks/qiskit/native-gates-qiskit This example demonstrates setting up an IonQ backend to use native gates, building a quantum circuit, transpiling it, and running it. ```python from qiskit import QuantumCircuit, transpile from qiskit_ionq import IonQProvider # Set up an IonQ backend to use native gates provider = IonQProvider() backend_native = provider.get_backend("simulator") ``` -------------------------------- ### Install Specific Qiskit and IonQ Provider Versions Source: https://docs.ionq.com/llms-full.txt Install specific versions of Qiskit and the IonQ Provider. Installing qiskit-ionq alone will also install a compatible Qiskit version if Qiskit is not already present. ```bash pip install qiskit==1.3 qiskit-ionq ``` -------------------------------- ### Install qiskit-ionq with a specific version Source: https://docs.ionq.com/sdks/qiskit/index Use pip to install a specific version of the qiskit-ionq package. This ensures compatibility with other installed Qiskit versions. ```shell pip install qiskit-ionq==1.3 ``` -------------------------------- ### GET /whoami Source: https://docs.ionq.com/ Gets information about the current token. ```APIDOC ## GET /whoami ### Description Gets information about the current token. ### Method GET ### Endpoint /whoami ### Parameters None ### Request Example None ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example { "example": "response body" } ``` -------------------------------- ### Import Libraries and Initialize Provider Source: https://docs.ionq.com/sdks/qbraid/index Imports necessary libraries from qbraid.runtime and qiskit. Initializes the IonQProvider and retrieves a device. This is the setup required before running quantum circuits. ```python from qbraid.runtime import IonQProvider from qiskit import QuantumCircuit provider = IonQProvider() device = provider.get_device("simulator") ``` -------------------------------- ### GET Get a Job's output Source: https://docs.ionq.com/api-reference/v0.3/jobs Retrieves the output or results of a completed job. ```APIDOC ## GET /jobs/{job_id}/output ### Description Retrieves the output of a specific job. ### Method GET ### Endpoint /jobs/{job_id}/output ### Parameters #### Path Parameters - **job_id** (string) - Required - The unique identifier of the job whose output is to be retrieved. ``` -------------------------------- ### Instantiate IonQ Devices in qBraid Source: https://docs.ionq.com/sdks/qbraid/index Demonstrates how to instantiate different IonQ devices, including 'qpu.forte-1', 'qpu.forte-enterprise-1', and the 'simulator', using the qBraid SDK. ```python ["qbraid.runtime.ionq.device.IonQDevice('qpu.forte-1')>, ["qbraid.runtime.ionq.device.IonQDevice('qpu.forte-enterprise-1')>, ["qbraid.runtime.ionq.device.IonQDevice('simulator')>] ``` -------------------------------- ### Run on Ideal Simulator with Cirq Source: https://docs.ionq.com/sdks/cirq/index This example demonstrates how to set up the IonQ service and build a basic quantum circuit using Cirq for execution on the ideal simulator. ```python import cirq import cirq_ionq # Set up the IonQ service service = cirq_ionq.Service() # Build a circuit circuit = cirq.Circuit() qubit = cirq.LineQubit(0) circuit.append(cirq.H(qubit)) circuit.append(cirq.CNOT(qubit, cirq.LineQubit(1))) # Run the circuit on the ideal simulator esult = service.run(circuit, shots=1000) print(result) ``` -------------------------------- ### Get Backends Source: https://docs.ionq.com/api-reference/v0.3/backends/get-backends Retrieves a list of all available backends. This is a GET request to the /backends endpoint. ```APIDOC ## GET /backends ### Description Retrieve a list of all available backends. ### Method GET ### Endpoint /backends ### Response #### Success Response (200) - **field1** (type) - Description #### Response Example { "example": "response body" } ``` -------------------------------- ### Swap Gate Example Source: https://docs.ionq.com/api-reference/v0.3/writing-quantum-programs Example of specifying a Swap gate between two target qubits. ```json {\"gate\": \"swap\", \"targets\": [0,1]} ``` -------------------------------- ### Example Output of Available Backends Source: https://docs.ionq.com/guides/sdks/qiskit This is an example of the output you should expect when listing available backends. It shows the different types of backends, such as simulators and QPUs, along with their identifiers. ```shellscript ["IonQSimulatorBackend('ionq_simulator')", "IonQPUBackend('ionq_qpu')"] ``` -------------------------------- ### Initialize IonQ Provider and Backend Source: https://docs.ionq.com/guides/sdks/qiskit Instantiate the IonQ provider and select a backend, such as a simulator. ```python provider = IonQProvider() simulator_backend = provider.get_backend("simulator") ``` -------------------------------- ### Hadamard Gate Example Source: https://docs.ionq.com/api-reference/v0.3/writing-quantum-programs Example of specifying a Hadamard gate in the JSON circuit format. ```json {\"gate\": \"h\", \"target\": 0} ``` -------------------------------- ### Get usage costs Source: https://docs.ionq.com/api-reference/v0.4 Gets usage cost broken down by time and job, project, or user. ```APIDOC ## GET /organizations/{organization_id}/usage ### Description Gets usage cost broken down by time and job, project, or user. ### Method GET ### Endpoint /organizations/{organization_id}/usage ``` -------------------------------- ### Setting up Environment with API Key Source: https://docs.ionq.com/sdks/qbraid/index Demonstrates how to set up your environment by either exporting your IonQ API key as an environment variable or passing it directly when initializing the IonQProvider. ```APIDOC ## Set up your environment By default, qBraid will look in your local environment for a variable named `IONQ_API_KEY`. Alternatively, you can set a temporary environment variable from your command line: ```bash export IONQ_API_KEY="your_api_key_here" ``` Or, pass your API key explicitly within your Python code: ```python import os from qbraid.runtime import IonQProvider # Load your API key from an environment variable named MY_IONQ_API_KEY my_api_key = os.getenv("MY_IONQ_API_KEY") provider = IonQProvider(my_api_key) ``` ``` -------------------------------- ### GET Get a Job's output Source: https://docs.ionq.com/api-reference/v0.3/multicircuit-jobs Retrieves the output or results of a completed quantum job. ```APIDOC ## GET /jobs/{id}/output ### Description Retrieves the output or results of a specific quantum job. This endpoint is typically used after a job has reached a terminal state (e.g., `COMPLETED`). ### Method GET ### Endpoint /jobs/{id}/output ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the job whose output is to be retrieved. ### Response #### Success Response (200) - **result** (object) - The results of the job execution. The structure of this object depends on the type of quantum computation performed. - **error** (object) - Information about any errors encountered during job execution. #### Response Example ```json { "result": { "00": 50, "11": 50 } } ``` ``` -------------------------------- ### Instantiate IonQ Devices Source: https://docs.ionq.com/sdks/qbraid/index Demonstrates how to instantiate different IonQ devices using the qBraid SDK. This includes physical devices like 'qpu.forte-1' and 'qpu.forte-enterprise-1', as well as the 'simulator'. Ensure your API key is valid and you have access to these devices. ```python ["qbraid.runtime.ionq.device.IonQDevice('qpu.forte-1')>, ["qbraid.runtime.ionq.device.IonQDevice('qpu.forte-enterprise-1')>, ["qbraid.runtime.ionq.device.IonQDevice('simulator')>"] ``` -------------------------------- ### Example Output for Listing Devices Source: https://docs.ionq.com/sdks/qbraid/index An example of the expected output when listing available devices using the IonQProvider. This illustrates the format of the device information returned. ```python [ 'A IonQ Quantum Computer', 'B IonQ Quantum Computer' ] ``` -------------------------------- ### Example Job Results Source: https://docs.ionq.com/guides/direct-api-submission This is an example of the dictionary containing job results returned by the probabilities endpoint. ```json { "0": 0.4619140625, "1": 0.5380859375 } ``` -------------------------------- ### Toffoli Gate Example Source: https://docs.ionq.com/api-reference/v0.3/writing-quantum-programs Example of specifying a Toffoli (multi-controlled NOT) gate with multiple control qubits. ```json {\"gate\": \"not\", \"target\": 0, \"controls\": [1, 2]} ``` -------------------------------- ### Set up IonQ Service Source: https://docs.ionq.com/sdks/cirq/index Initialize the IonQ service object to interact with IonQ's quantum hardware. This is the first step after importing libraries. ```python # Set up the IonQ service service = cirq_ionq.Service() ```