### Install qnexus with Qiskit extras Source: https://docs.quantinuum.com/nexus/trainings/getting_started.html Installation command including optional dependencies for running Qiskit simulations with noise models. ```bash pip install qnexus[qiskit] ``` -------------------------------- ### Install pytket-qir Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/pytket_to_qir.ipynb.txt Install the pytket-qir extension via pip. ```bash pip install pytket-qir ``` -------------------------------- ### Install qnexus via pip Source: https://docs.quantinuum.com/nexus/_sources/trainings/getting_started.md.txt Standard installation command for the qnexus Python package. ```bash pip install qnexus ``` -------------------------------- ### Creating and executing a job Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/saving_refs.ipynb.txt Initializes a project, uploads a circuit, and starts an execution job on a Quantinuum backend. ```python job_name = f"Job from {datetime.now()}" my_project_ref = qnx.projects.get_or_create(name="My Project") my_circuit_ref = qnx.circuits.upload( name=f"My Circuit from {datetime.now()}", circuit=Circuit(2).ZZPhase(0.5, 0, 1).measure_all(), project=my_project_ref, ) my_execute_job_ref = qnx.start_execute_job( programs=[my_circuit_ref], backend_config=qnx.QuantinuumConfig(device_name="H2-1LE"), n_shots=[100], name=job_name, project=my_project_ref, ) ``` -------------------------------- ### Install HUGR-QIR Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/guppy_to_qir.ipynb.txt Install the required package via pip. ```bash pip install hugr-qir ``` -------------------------------- ### Start an execution job Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/getting_started.ipynb.txt Submits a compiled circuit for execution on a quantum target. ```python ref_execute_job = qnx.start_execute_job( programs=[ref_compiled_circuit], n_shots=[100], backend_config=config, name=f"execution-job-{jobname_suffix}", ) ``` -------------------------------- ### Retrieve Circuits with Filters Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/circuits.html Examples demonstrating how to fetch circuits using project references or name-based filtering. ```python >>> import qnexus as qnx >>> all_circuits = qnx.circuits.get_all(project=project_ref) >>> all_circuits.df() ``` ```python >>> qnx.circuits.get_all(name_like="bell", project=project_ref) ``` -------------------------------- ### WebAssembly Callout Implementation Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/index.ipynb.txt Example showing how to obtain a Wasm context and execute Wasm calls, along with the required function declarations. ```llvm body: [...] ; Obtain a Wasm context %ctx = call i64 @___get_wasm_context(i64 0) ; Execute Wasm calls %rti = call i64 @round_to_int(i64 %ctx, double 3.7) %abs = call i64 @abs_i64(i64 %ctx, i64 -42) %sqf = call i64 @sqrt_floor(i64 %ctx, double 10.0) %fct = call i64 @factorial(i64 %ctx, i64 5) %avg = call double @average(i64 %ctx, double 10.0, double 20.0) [...] ; Declarations ; Wasm init function declare i64 @___get_wasm_context(i64) ; Wasm function declarations declare i64 @round_to_int(i64, double) #2 declare i64 @abs_i64(i64, i64) #2 declare i64 @sqrt_floor(i64, double) #2 declare i64 @factorial(i64, i64) #2 declare double @average(i64, double, double) #2 ``` -------------------------------- ### Retrieve all jobs with filters Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/jobs.html Examples of using qnx.jobs.get_all to fetch jobs, including basic retrieval and filtering by job status. ```python >>> import qnexus as qnx >>> all_jobs = qnx.jobs.get_all(project=project_ref) >>> all_jobs.df() ``` ```python >>> from qnexus.models.job_status import JobStatusEnum >>> errored = qnx.jobs.get_all( ... project=project_ref, ... job_status=[JobStatusEnum.ERROR], ... ) ``` -------------------------------- ### Start the compilation job Source: https://docs.quantinuum.com/nexus/trainings/notebooks/basics/hypertket/qubit_reuse.html Submits the circuit for compilation with the specified HyperTket configuration. ```python compile_job = qnexus.start_compile_job( programs=[ref_circuit], name=f"compile-job-1-{job_name_suffix}", hypertket_config=hypertket_config, backend_config=qntm_config, optimisation_level=0 ) ``` -------------------------------- ### Define QIR Entry Point and Attributes Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/index.ipynb.txt Example of defining a QIR entry point with required attributes for qubit and result counts. ```llvm declare void @__quantum__qis__reset__body(%Qubit*) #1 attributes #0 = { "entry_point" "output_labeling_schema" "qir_profiles"="adaptive_profile" "required_num_qubits"="5" "required_num_results"="6" } attributes #1 = { "irreversible" } ``` -------------------------------- ### Example Output Record Format Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/index.ipynb.txt Shows the expected structure of output records for multiple shots, including headers and metadata. ```bash HEADER schema_id labeled HEADER schema_version 1.0 START METADATA entry_point METADATA qir_profiles base_profile METADATA required_num_qubits 5 METADATA required_num_results 5 METADATA output_labeling_schema labeled OUTPUT INT 42 0_i END 0 START OUTPUT INT 41 0_i END 0 START OUTPUT INT 42 0_i END 0 ``` -------------------------------- ### Start Compilation Job Source: https://docs.quantinuum.com/nexus/trainings/notebooks/basics/hypertket/qubit_reuse.html Initiates a compilation job with specific HyperTket and backend configurations. ```python compile_job = qnexus.start_compile_job( programs=[ref_circuit], name=f"compile-job-5-{job_name_suffix}", hypertket_config=hypertket_config, backend_config=qntm_config, optimisation_level=0 ) ``` ```python compile_job = qnexus.start_compile_job( programs=[ref_circuit], name=f"compile-job-6-{job_name_suffix}", hypertket_config=hypertket_config, backend_config=qntm_config, optimisation_level=0 ) ``` ```python compile_job = qnexus.start_compile_job( programs=[ref_circuit], name=f"compile-job-7-{job_name_suffix}", hypertket_config=hypertket_config, backend_config=qntm_config, optimisation_level=0 ) ``` ```python compile_job = qnexus.start_compile_job( programs=[ref_circuit], name=f"compile-job-8-{job_name_suffix}", hypertket_config=hypertket_config, backend_config=qntm_config, optimisation_level=0 ) ``` -------------------------------- ### Get or Create a Project Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/projects.html Retrieves an existing project by name or creates a new one if it does not exist. ```python >>> import qnexus as qnx >>> project_ref = qnx.projects.get_or_create(name="MyProject") >>> project_ref = qnx.projects.get_or_create( ... name="MyProject", ... description="A new experiment", ... properties={"team": "quantum"}, ... ) ``` -------------------------------- ### Retrieve Credentials Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/credentials.html Use these examples to fetch all saved credentials or filter them by a specific issuer. ```python >>> import qnexus as qnx >>> all_creds = qnx.credentials.get_all() >>> all_creds.df() ``` ```python >>> from qnexus.models import CredentialIssuer >>> qnx.credentials.get_all(issuer=CredentialIssuer.IBMQ) ``` -------------------------------- ### Start a compilation job Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/getting_started.ipynb.txt Initiates a compilation job for a given circuit reference using a specified backend configuration. ```python ref_compile_job = qnx.start_compile_job( programs=[ref], backend_config=config, optimisation_level=2, name=f"compilation-job-{jobname_suffix}", ) ``` -------------------------------- ### Example Array Output Recording Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/index.ipynb.txt Demonstrates recording two arrays of measurement results in a QIR program. ```llvm @0 = internal constant [5 x i8] c"0_0a\00" @1 = internal constant [7 x i8] c"1_0a0r\00" @2 = internal constant [5 x i8] c"2_1a\00" @3 = internal constant [7 x i8] c"3_1a0r\00" @4 = internal constant [7 x i8] c"4_1a1r\00" call void @__quantum__rt__array_record_output(i64 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0)) call void @__quantum__rt__result_record_output(%Result* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @1, i32 0, i32 0)) call void @__quantum__rt__array_record_output(i64 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0)) ``` -------------------------------- ### Guppy Imports and Setup Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/guppy_to_qir.ipynb.txt Standard imports required for defining Guppy functions and utilizing quantum primitives. ```python from pathlib import Path from typing import no_type_check from guppylang import guppy from guppylang.defs import GuppyFunctionDefinition from guppylang.std.angles import angle from guppylang.std.builtins import array, owned from guppylang.std.platform import result from guppylang.std.qsystem.random import RNG from guppylang.std.quantum import crz, cx, h, measure, qubit ``` -------------------------------- ### Record array and result outputs in QIR Source: https://docs.quantinuum.com/nexus/trainings/notebooks/basics/qir/index.html Example showing how to record array lengths and individual result items within a QIR program. ```LLVM IR @0 = internal constant [5 x i8] c"0_0a\00" @1 = internal constant [7 x i8] c"1_0a0r\00" @2 = internal constant [5 x i8] c"2_1a\00" @3 = internal constant [7 x i8] c"3_1a0r\00" @4 = internal constant [7 x i8] c"4_1a1r\00" call void @__quantum__rt__array_record_output(i64 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @0, i32 0, i32 0)) call void @__quantum__rt__result_record_output(%Result* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @1, i32 0, i32 0)) call void @__quantum__rt__array_record_output(i64 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0)) call void @__quantum__rt__result_record_output(%Result* nonnull inttoptr (i64 0 to %Result*), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @3, i32 0, i32 0)) call void @__quantum__rt__result_record_output(%Result* nonnull inttoptr (i64 0 to %Result*), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @4, i32 0, i32 0)) ret void ``` -------------------------------- ### Retrieve available devices Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/devices.html Use these examples to fetch a list of all available devices or filter them by issuer. The returned object supports conversion to a pandas DataFrame. ```python >>> import qnexus as qnx >>> from qnexus.models import IssuerEnum >>> all_devices = qnx.devices.get_all() >>> all_devices.df() ``` ```python >>> quantinuum_devices = qnx.devices.get_all(issuers=[IssuerEnum.QUANTINUUM]) ``` -------------------------------- ### Example Tuple Output Recording Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/index.ipynb.txt A QIR program snippet demonstrating how to record a tuple containing a measurement result and a double value. ```llvm @0 = internal constant [4 x i8] c"0_t\00" @1 = internal constant [6 x i8] c"1_t0r\00" @2 = internal constant [6 x i8] c"2_t1d\00" call void @__quantum__rt__tuple_record_output(i64 2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @0, i32 0, i32 0)) call void @__quantum__rt__result_record_output(%Result* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @1, i32 0, i32 0)) call void @__quantum__rt__double_record_output(double %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @2, i32 0, i32 0)) ret void ``` -------------------------------- ### Import qnexus library Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/alternate_backends/devices_credentials.ipynb.txt Initialize the qnexus library for interacting with the platform. ```python import qnexus as qnx ``` -------------------------------- ### Setting up the Nexus project Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/knowledge_articles/labelling_workflow_data_with_properties.ipynb.txt Initialize or retrieve a project and set it as the active context. ```python my_project = qnx.projects.get_or_create(name="My Properties Example Project") qnx.context.set_active_project(my_project) ``` -------------------------------- ### Execute Wasm callouts on Helios Source: https://docs.quantinuum.com/nexus/trainings/notebooks/basics/qir/index.html Example of obtaining a Wasm context and executing Wasm calls on Helios, which supports both i64 and double types. ```llvm body: [...] ; Obtain a Wasm context %ctx = call i64 @___get_wasm_context(i64 0) ; Execute Wasm calls %rti = call i64 @round_to_int(i64 %ctx, double 3.7) %abs = call i64 @abs_i64(i64 %ctx, i64 -42) %sqf = call i64 @sqrt_floor(i64 %ctx, double 10.0) %fct = call i64 @factorial(i64 %ctx, i64 5) %avg = call double @average(i64 %ctx, double 10.0, double 20.0) [...] ; Declarations ; Wasm init function declare i64 @___get_wasm_context(i64) ; Wasm function declarations declare i64 @round_to_int(i64, double) #2 declare i64 @abs_i64(i64, i64) #2 declare i64 @sqrt_floor(i64, double) #2 declare i64 @factorial(i64, i64) #2 declare double @average(i64, double, double) #2 ; Wasm attribute attributes #2 = { "wasm" } ``` -------------------------------- ### Initialize Nexus environment Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/refs_nexus_iterator.ipynb.txt Import necessary libraries and the qnexus package. ```python from datetime import datetime, timedelta from pytket import Circuit import qnexus as qnx ``` -------------------------------- ### Preparing Projects and Circuits Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/alternate_backends/index.ipynb.txt Setting up a project and uploading a circuit for use in jobs. ```python my_project_ref = qnx.projects.get_or_create(name="My Nexus Project") my_circuit_ref = qnx.circuits.upload( name="My Circuit", circuit=Circuit(2).H(0).CX(0, 1).measure_all(), project=my_project_ref, ) ``` -------------------------------- ### cost_confidence Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/jobs.html Get the HQC cost and confidence of a job from a JobRef. ```APIDOC ## cost_confidence ### Description Get the HQC cost and confidence of a job from a JobRef. Returns a list of tuples of (cost, confidence) for each job item. ### Parameters - **job** (CompileJobRef | ExecuteJobRef) - Required - **scope** (ScopeFilterEnum) - Optional - Default: ScopeFilterEnum.USER ### Response - **list[tuple[float, float]]** - A list of tuples containing cost and confidence. ``` -------------------------------- ### Scope Filter Source: https://docs.quantinuum.com/nexus/_modules/qnexus/models/filters.html Filter model for scope with an example of usage. ```python class ScopeFilter(BaseModel): """Filter by scope. Example: >>> import qnexus as qnx >>> from qnexus.models.scope import ScopeFilterEnum >>> qnx.projects.get_all(scope=ScopeFilterEnum.ORG_ADMIN) """ scope: ScopeFilterEnum = ScopeFilterEnum.USER model_config = ConfigDict(use_enum_values=True) ``` -------------------------------- ### Main Entry Point with Quantum Operations Source: https://docs.quantinuum.com/nexus/_downloads/964a5215f4c21de7e535e05c78ebcec9/ir_fn.ll Demonstrates the main entry point of a QIR program, including environment initialization, quantum gate sequences, measurement, and conditional branching based on measurement results. ```llvm define i64 @main() local_unnamed_addr #0 { entry: ; calls to initialize the execution environment call void @__quantum__rt__initialize(i8* null) br label %body body: ; preds = %entry ; calling an IR defined quantum function call void @swap(%Qubit* null, %Qubit* nonnull inttoptr (i64 1 to %Qubit*)) tail call void @__quantum__qis__h__body(%Qubit* null) tail call void @__quantum__qis__cnot__body(%Qubit* null, %Qubit* nonnull inttoptr (i64 1 to %Qubit*)) tail call void @__quantum__qis__h__body(%Qubit* nonnull inttoptr (i64 2 to %Qubit*)) tail call void @__quantum__qis__cnot__body(%Qubit* nonnull inttoptr (i64 2 to %Qubit*), %Qubit* nonnull inttoptr (i64 4 to %Qubit*)) tail call void @__quantum__qis__h__body(%Qubit* nonnull inttoptr (i64 3 to %Qubit*)) tail call void @__quantum__qis__cnot__body(%Qubit* nonnull inttoptr (i64 3 to %Qubit*), %Qubit* nonnull inttoptr (i64 5 to %Qubit*)) tail call void @__quantum__qis__cnot__body(%Qubit* nonnull inttoptr (i64 1 to %Qubit*), %Qubit* nonnull inttoptr (i64 2 to %Qubit*)) tail call void @__quantum__qis__h__body(%Qubit* nonnull inttoptr (i64 1 to %Qubit*)) tail call void @__quantum__qis__mz__body(%Qubit* nonnull inttoptr (i64 1 to %Qubit*), %Result* writeonly null) tail call void @__quantum__qis__reset__body(%Qubit* nonnull inttoptr (i64 1 to %Qubit*)) %0 = tail call i1 @__quantum__rt__read_result(%Result* readonly null) br i1 %0, label %then__1, label %continue__1 ; conditional quantum gate (only one in this block, but many can appear and the full quantum instruction set should be usable) then__1: ; preds = %body tail call void @__quantum__qis__z__body(%Qubit* nonnull inttoptr (i64 4 to %Qubit*)) br label %continue__1 continue__1: ; preds = %then__1, %body tail call void @__quantum__qis__mz__body(%Qubit* nonnull inttoptr (i64 2 to %Qubit*), %Result* writeonly nonnull inttoptr (i64 1 to %Result*)) tail call void @__quantum__qis__reset__body(%Qubit* nonnull inttoptr (i64 2 to %Qubit*)) %1 = tail call i1 @__quantum__rt__read_result(%Result* readonly nonnull inttoptr (i64 1 to %Result*)) br i1 %1, label %then__2, label %continue__2 then__2: ; preds = %continue__1 tail call void @__quantum__qis__x__body(%Qubit* nonnull inttoptr (i64 4 to %Qubit*)) br label %continue__2 continue__2: ; preds = %then__2, %continue__1 tail call void @__quantum__qis__cnot__body(%Qubit* nonnull inttoptr (i64 4 to %Qubit*), %Qubit* nonnull inttoptr (i64 3 to %Qubit*)) tail call void @__quantum__qis__h__body(%Qubit* nonnull inttoptr (i64 4 to %Qubit*)) tail call void @__quantum__qis__mz__body(%Qubit* nonnull inttoptr (i64 4 to %Qubit*), %Result* writeonly nonnull inttoptr (i64 2 to %Result*)) tail call void @__quantum__qis__reset__body(%Qubit* nonnull inttoptr (i64 4 to %Qubit*)) %2 = tail call i1 @__quantum__rt__read_result(%Result* readonly nonnull inttoptr (i64 2 to %Result*)) br i1 %2, label %then__3, label %continue__3 then__3: ; preds = %continue__2 tail call void @__quantum__qis__z__body(%Qubit* nonnull inttoptr (i64 5 to %Qubit*)) br label %continue__3 continue__3: ; preds = %then__3, %continue__2 tail call void @__quantum__qis__mz__body(%Qubit* nonnull inttoptr (i64 3 to %Qubit*), %Result* writeonly nonnull inttoptr (i64 3 to %Result*)) tail call void @__quantum__qis__reset__body(%Qubit* nonnull inttoptr (i64 3 to %Qubit*)) %3 = tail call i1 @__quantum__rt__read_result(%Result* readonly nonnull inttoptr (i64 3 to %Result*)) br i1 %3, label %then__4, label %continue__4 then__4: ; preds = %continue__3 tail call void @__quantum__qis__x__body(%Qubit* nonnull inttoptr (i64 5 to %Qubit*)) br label %continue__4 ``` -------------------------------- ### GET /api/jobs/v1beta3/{job.id} Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/jobs.html Retrieves the HQC cost of a job from a JobRef. ```APIDOC ## GET /api/jobs/v1beta3/{job.id} ### Description Get the HQC cost of a job from a JobRef. ### Method GET ### Endpoint /api/jobs/v1beta3/{job.id} ### Parameters #### Path Parameters - **job.id** (string) - Required - The ID of the job. #### Query Parameters - **scope** (ScopeFilterEnum) - Optional - The scope filter for the request. ``` -------------------------------- ### GET /api/circuits/v1beta2/{id} Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/circuits.html Fetches a circuit reference by its unique identifier. ```APIDOC ## GET /api/circuits/v1beta2/{id} ### Description Utility method for fetching directly by a unique identifier. ### Method GET ### Endpoint /api/circuits/v1beta2/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the circuit. #### Query Parameters - **scope** (string) - Optional - The scope filter for the request. ``` -------------------------------- ### Create Project and Upload Circuit Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/jobs_results.ipynb.txt Sets up a project and uploads a circuit to Nexus for use in jobs. ```python my_job_name_prefix = datetime.now() my_project_ref = qnx.projects.get_or_create(name="My Project") my_circuit_ref = qnx.circuits.upload( name=f"My Circuit from {datetime.now()}", circuit=Circuit(2).H(0).CX(0, 1).measure_all(), project=my_project_ref, ) ``` -------------------------------- ### Initialize QNexus Project Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/knowledge_articles/vqe_example.ipynb.txt Creates a new project in QNexus and sets it as the active context for subsequent operations. ```python # set up the project project_ref = qnx.projects.create( name=f"VQE_example_{str(datetime.now())}", description="A VQE done with qnexus", ) # set this in the context qnx.context.set_active_project(project_ref) ``` -------------------------------- ### get Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/hugr.html Retrieves a single HUGR reference based on provided filters. ```APIDOC ## get ### Description Fetches a single HUGR reference. Throws an exception if the provided filters do not resolve to exactly one object. ### Parameters - **id** (Union[UUID, str]) - Optional - Unique identifier of the HUGR. - **name** (str) - Optional - Exact name of the HUGR. - **name_like** (str) - Optional - Partial name match. - **creator_email** (list[str]) - Optional - Filter by creator email. - **project** (ProjectRef) - Optional - Filter by project reference. - **properties** (PropertiesDict) - Optional - Filter by properties. - **created_before** (datetime) - Optional - Filter by creation date. - **created_after** (datetime) - Optional - Filter by creation date. - **modified_before** (datetime) - Optional - Filter by modification date. - **modified_after** (datetime) - Optional - Filter by modification date. - **sort_filters** (list[SortFilterEnum]) - Optional - Sorting criteria. - **page_number** (int) - Optional - Page number for pagination. - **page_size** (int) - Optional - Number of items per page. - **scope** (ScopeFilterEnum) - Optional - Scope filter (default: USER). ``` -------------------------------- ### Get a single role Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/roles.html Retrieves a specific role definition by its name. ```python >>> import qnexus as qnx >>> reader_role = qnx.roles.get("Maintainer") ``` -------------------------------- ### Create a New Project Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/projects.html Initializes a new project in Nexus with a specified name and optional description. ```python >>> import qnexus as qnx >>> project_ref = qnx.projects.create( ... name="ProjectUnobtanium", ... description="Chemistry experiments on unobtanium", ... ) ``` -------------------------------- ### GET /api/users/v1beta2/me Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/users.html Retrieves the profile information for the currently authenticated user. ```APIDOC ## GET /api/users/v1beta2/me ### Description Retrieves the profile information for the currently authenticated user. ### Method GET ### Endpoint /api/users/v1beta2/me ### Response #### Success Response (200) - **data** (object) - The user resource object containing attributes and ID. - **data.id** (string) - The unique identifier of the user. - **data.attributes.display_name** (string) - The display name of the user. ``` -------------------------------- ### Initialize qnexus and list teams Source: https://docs.quantinuum.com/nexus/trainings/notebooks/basics/teams_roles.html Import the necessary modules and retrieve a list of teams the current user belongs to. ```python from datetime import datetime import qnexus as qnx ``` ```python # List teams I am a member of qnx.teams.get_all().df() ``` -------------------------------- ### Devices Filter Source: https://docs.quantinuum.com/nexus/_modules/qnexus/models/filters.html Filter model for device details with an example of usage. ```python class DevicesFilter(BaseModel): """Filter by device details. Example: >>> import qnexus as qnx >>> from qnexus.models import IssuerEnum >>> qnx.devices.get_all(issuers=[IssuerEnum.QUANTINUUM]) """ backend: list[str] | None = None region: str | None = None ibm_instance: str | None = None ibm_region: str | None = None credential_ids: list[str] | None = None credential_names: list[str] | None = None is_local: bool | None = None ``` -------------------------------- ### Get result distribution Source: https://docs.quantinuum.com/nexus/trainings/notebooks/basics/getting_started.html Extracts the probability distribution from a downloaded backend result. ```python backend_result.get_distribution() ``` -------------------------------- ### Configuring Backend Targets Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/alternate_backends/index.ipynb.txt Creating configuration objects for specific quantum backends. ```python # Create a configuration to target the H2-1LE noiseless simulator my_quantinuum_config = qnx.QuantinuumConfig( device_name="H2-1LE", ) ``` ```python # Create a configuration to target the IBMQ Kyiv device through the open plan my_ibmq_config = qnx.IBMQConfig( instance="default-us", project="main", ) ``` -------------------------------- ### GET /api/resources/v1beta2/{resource_id}/assignments Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/roles.html Retrieves the role assignments for a specific resource. ```APIDOC ## GET /api/resources/v1beta2/{resource_id}/assignments ### Description Check the assignments on a particular resource. ### Method GET ### Endpoint /api/resources/v1beta2/{resource_id}/assignments ### Parameters #### Path Parameters - **resource_id** (string) - Required - The ID of the resource to check assignments for. #### Query Parameters - **scope** (string) - Optional - The scope filter for the assignments (e.g., USER). ``` -------------------------------- ### Configure Matrix Product State Simulator Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/selene_examples.ipynb.txt Sets up a SelenePlus configuration using the MatrixProductStateSimulator. ```python config = qnx.SelenePlusConfig( n_qubits=N, simulator=qnx.models.MatrixProductStateSimulator( backend="auto", seed=123141, zero_threshold=0.01, chi=50, ), ) selene_lean_job_ref = qnx.start_execute_job( programs=[many_t_gates_hugr_program_ref], ``` -------------------------------- ### GET /api/roles/v1beta Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/roles.html Retrieves the definitions of all available role-based access control assignments. ```APIDOC ## GET /api/roles/v1beta ### Description Get the definitions of possible role-based access control assignments. ### Method GET ### Endpoint /api/roles/v1beta ``` -------------------------------- ### Compiling and Executing a Circuit on Braket Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/alternate_backends/braket_examples.ipynb.txt Demonstrates the full workflow of creating a project, uploading a circuit, compiling it for the Braket backend, and executing it. ```python my_project_ref = qnx.projects.get_or_create(name="My AWS Braket Project") circuit = Circuit(2).H(0).CX(0, 1).measure_all() my_circuit_ref = qnx.circuits.upload( name=f"My AWS Braket Circuit from {datetime.now()}", circuit=circuit, project=my_project_ref, ) compile_job = qnx.start_compile_job( programs=[my_circuit_ref], name=f"My Compile Job from {datetime.now()}", optimisation_level=1, backend_config=braket_config, project=my_project_ref, ) qnx.jobs.wait_for(compile_job) compiled_circuits = [item.get_output() for item in qnx.jobs.results(compile_job)] execute_job_ref = qnx.start_execute_job( programs=compiled_circuits, name=f"My Execute Job from {datetime.now()}", n_shots=[100], backend_config=braket_config, project=my_project_ref, ) qnx.jobs.wait_for(execute_job_ref) # Retrieve a ExecutionResultRef for every Circuit that was executed execute_job_result_refs = qnx.jobs.results(execute_job_ref) # Get a pytket BackendResult for the execution result = execute_job_result_refs[0].download_result() result.get_counts() ``` -------------------------------- ### GET /api/teams/v1beta2 Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/teams.html Retrieves a list of all teams available within the specified scope. ```APIDOC ## GET /api/teams/v1beta2 ### Description Retrieves a list of all teams available within the specified scope. ### Method GET ### Endpoint /api/teams/v1beta2 ### Parameters #### Query Parameters - **scope** (ScopeFilterEnum) - Optional - The scope filter to apply (default: USER). ``` -------------------------------- ### GET /api/quotas/v1beta3/guard Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/quotas.html Checks if the current user has available quota for a specific operation. ```APIDOC ## GET /api/quotas/v1beta3/guard ### Description Checks if the current user has available quota for a specific operation. ### Method GET ### Endpoint /api/quotas/v1beta3/guard ### Parameters #### Query Parameters - **name** (string) - Required - The name of the quota to check. - **user_id** (string) - Required - The ID of the user. ``` -------------------------------- ### Importing Required Modules Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/alternate_backends/braket_examples.ipynb.txt Initial imports for datetime, pytket, and qnexus. ```python from datetime import datetime from pytket import Circuit import qnexus as qnx ``` -------------------------------- ### GET /api/quotas/v1beta3 Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/quotas.html Retrieves details for a specific quota by name for the current user. ```APIDOC ## GET /api/quotas/v1beta3 ### Description Retrieves details for a specific quota by name for the current user. ### Method GET ### Endpoint /api/quotas/v1beta3 ### Parameters #### Query Parameters - **entity_type** (string) - Required - The type of entity (e.g., "user"). - **entity_id** (string) - Required - The ID of the user. - **name** (string) - Required - The name of the quota (e.g., "compilation", "simulation", "jupyterhub", "database_usage"). - **include_usage** (boolean) - Required - Whether to include usage statistics. ``` -------------------------------- ### Job Type Filter Source: https://docs.quantinuum.com/nexus/_modules/qnexus/models/filters.html Filter model for job types with an example of usage. ```python class JobTypeFilter(BaseModel): """Filter by job type. Example: >>> import qnexus as qnx >>> from qnexus.models.references import JobType >>> qnx.jobs.get_all(job_type=[JobType.EXECUTE]) """ job_type: list[JobType] | None = Field( default=[JobType.EXECUTE, JobType.COMPILE], serialization_alias="filter[job_type]", description="Filter by job_type", ) model_config = ConfigDict(use_enum_values=True) ``` -------------------------------- ### Start SSH Agent Source: https://docs.quantinuum.com/nexus/_sources/user_guide/lab.md.txt Initializes the SSH agent in the current shell session. ```bash eval "$(ssh-agent -s)" ``` -------------------------------- ### Initialize Project and Context Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/getting_started.ipynb.txt Retrieves or creates a project and sets it as the active context for the current session. ```python import qnexus as qnx project = qnx.projects.get_or_create(name="Nexus-Workflow-Demonstration") qnx.context.set_active_project(project) ``` -------------------------------- ### Execute a Job Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/getting_started.ipynb.txt Starts a new execution job on the specified backend device. ```python # Lets start a job (please note this example assumes you have access to the H2-1E device) ref_execute_job1 = qnx.start_execute_job( programs=[ref_compiled_circuit], n_shots=[100], backend_config=qnx.QuantinuumConfig(device_name="H2-1E"), name=f"execution-job-to-cancel-{jobname_suffix}", ) ``` -------------------------------- ### Create and inspect a project Source: https://docs.quantinuum.com/nexus/trainings/notebooks/basics/projects_properties_context.html Create a new project and retrieve its basic information as a DataFrame. ```python # Get a ProjectRef my_project_ref = qnx.projects.create(name=f"My Project from {datetime.now()}") # Show basic information about the project my_project_ref.df() ``` -------------------------------- ### Initialize Nexus SDK Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/teams_roles.ipynb.txt Import the necessary modules to interact with the Nexus platform. ```python from datetime import datetime import qnexus as qnx ``` -------------------------------- ### GET /api/teams/v1beta2 (Filter by Name) Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/teams.html Retrieves a single team by filtering on the team name. ```APIDOC ## GET /api/teams/v1beta2 ### Description Retrieves a single team by filtering on the team name. Throws an exception if the filters do not match exactly one object. ### Method GET ### Endpoint /api/teams/v1beta2 ### Parameters #### Query Parameters - **filter[team][name]** (string) - Required - The name of the team to retrieve. - **scope** (ScopeFilterEnum) - Optional - The scope filter to apply (default: USER). ``` -------------------------------- ### GET /api/quotas/v1beta Source: https://docs.quantinuum.com/nexus/_modules/qnexus/client/quotas.html Retrieves all quotas for the current user, including current usage statistics. ```APIDOC ## GET /api/quotas/v1beta ### Description Retrieves all quotas for the current user, including usage information. ### Method GET ### Endpoint /api/quotas/v1beta ### Parameters #### Query Parameters - **entity_type** (string) - Required - The type of entity (e.g., "user"). - **entity_id** (string) - Required - The ID of the user. - **include_usage** (boolean) - Required - Whether to include usage statistics. ``` -------------------------------- ### Generate QIR Output Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/pytket_to_qir.ipynb.txt Example of the resulting QIR representation generated from a pytket circuit. ```llvm ; ModuleID = 'conditional' source_filename = "conditional" %Qubit = type opaque %Result = type opaque @0 = internal constant [2 x i8] c"a\00" @1 = internal constant [2 x i8] c"b\00" @2 = internal constant [2 x i8] c"c\00" @3 = internal constant [2 x i8] c"d\00" define void @main() #0 { entry: call void @__quantum__qis__h__body(%Qubit* null) call void @__quantum__qis__h__body(%Qubit* inttoptr (i64 1 to %Qubit*)) call void @__quantum__qis__h__body(%Qubit* inttoptr (i64 2 to %Qubit*)) call void @__quantum__qis__h__body(%Qubit* null) br i1 false, label %condb0, label %contb0 condb0: ; preds = %entry br label %contb0 contb0: ; preds = %condb0, %entry %0 = phi i64 [ 0, %condb0 ], [ 0, %entry ] call void @__quantum__qis__mz__body(%Qubit* inttoptr (i64 2 to %Qubit*), %Result* inttoptr (i64 2 to %Result*)) %1 = call i1 @__quantum__rt__read_result(%Result* inttoptr (i64 2 to %Result*)) %2 = zext i1 %1 to i64 %3 = mul i64 %2, 4 %4 = or i64 %3, %0 %5 = sub i64 1, %2 %6 = mul i64 %5, 4 %7 = xor i64 9223372036854775807, %6 %8 = and i64 %7, %4 call void @__quantum__qis__mz__body(%Qubit* inttoptr (i64 1 to %Qubit*), %Result* inttoptr (i64 1 to %Result*)) %9 = call i1 @__quantum__rt__read_result(%Result* inttoptr (i64 1 to %Result*)) %10 = zext i1 %9 to i64 %11 = mul i64 %10, 8 %12 = or i64 %11, %8 %13 = sub i64 1, %10 %14 = mul i64 %13, 8 %15 = xor i64 9223372036854775807, %14 %16 = and i64 %15, %12 ``` -------------------------------- ### Initialize WasmFileHandler and Circuit Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/pytket_to_qir.ipynb.txt Sets up a Wasm file handler and a pytket circuit with classical registers to prepare for Wasm function integration. ```python from pytket import wasm from pytket.circuit import Bit, Circuit, Qubit from pytket.wasm import WasmFileHandler w = WasmFileHandler("testfile.wasm") c = Circuit(6, 6) c0 = c.add_c_register("c0", 3) c1 = c.add_c_register("c1", 4) c2 = c.add_c_register("c2", 5) c.add_wasm_to_reg("multi", w, [c0, c1], [c2]) c.add_wasm_to_reg("add_one", w, [c2], [c2]) c.add_wasm_to_reg("no_return", w, [c2], []) c.add_wasm_to_reg("init", w, [], []) c.add_wasm_to_reg("no_parameters", w, [], [c2]) ``` -------------------------------- ### Configure Backend Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/getting_started.ipynb.txt Instantiates a QuantinuumConfig to target a specific hardware or emulator backend. ```python config = qnx.QuantinuumConfig(device_name="H2-Emulator") ``` -------------------------------- ### Job Status Filter Source: https://docs.quantinuum.com/nexus/_modules/qnexus/models/filters.html Filter model for job statuses with an example of usage in a query. ```python class JobStatusFilter(BaseModel): """Job status filter. Example: >>> import qnexus as qnx >>> from qnexus.models.job_status import JobStatusEnum >>> qnx.jobs.get_all(job_status=[JobStatusEnum.RUNNING, JobStatusEnum.QUEUED]) """ status: list[JobStatusString] | None = Field( default=[ # type: ignore "COMPLETED", "QUEUED", "SUBMITTED", "RUNNING", "CANCELLED", "ERROR", "DEPLETED", "TERMINATED", ], serialization_alias="filter[status][status]", description="Filter by job status", ) @staticmethod def convert_status_filters( status_filters: list[JobStatusEnum], ) -> list[JobStatusString]: """Convert SortFilterEnum to SortFilterString.""" return [ jobstatusenum_to_string[status_filter] for status_filter in status_filters ] ``` -------------------------------- ### Importing required libraries Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/knowledge_articles/labelling_workflow_data_with_properties.ipynb.txt Initial imports for handling circuits, Pauli gadgets, and Nexus connectivity. ```python from datetime import datetime from pytket import Circuit from pytket.circuit import PauliExpBox, QControlBox from pytket.pauli import Pauli from qiskit_aer import noise import qnexus as qnx ``` -------------------------------- ### Start a New Execution Job Source: https://docs.quantinuum.com/nexus/trainings/notebooks/basics/jobs_results.html Initiates a new execution job for circuit processing. ```python other_execute_job_ref = qnx.start_execute_job( programs=compiled_circuits, name=f"{my_job_name_prefix}_execute_other", n_shots=[100] * len(compiled_circuits), backend_config=qnx.QuantinuumConfig(device_name="H2-1LE"), project=my_project_ref, ) ``` -------------------------------- ### Importing required libraries Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/selene_examples.ipynb.txt Initial imports for Guppy quantum programming and Nexus interaction. ```python from datetime import datetime from pprint import pprint from typing import no_type_check from guppylang import guppy from guppylang.std.builtins import array, comptime, result from guppylang.std.quantum import cx, h, measure, qubit, t import qnexus as qnx ``` -------------------------------- ### Get Symbolic Circuit Reference Source: https://docs.quantinuum.com/nexus/trainings/notebooks/knowledge_articles/vqe_example.html Retrieves the symbolic circuit definition used in the VQE workflow. ```python # Get the symbolic circuit symbolic_circuit_ref = qnx.circuits.get(name_like="ansatz_circuit") ``` -------------------------------- ### Configure Project and Job Metadata Source: https://docs.quantinuum.com/nexus/_sources/trainings/notebooks/basics/qir/qir_submission.ipynb.txt Sets up the active project and prepares a timestamped suffix for job naming. ```python import datetime project = qnx.projects.get_or_create(name="QIR-Demonstration") qnx.context.set_active_project(project) qir_name = "QIR Bell circuit" jobname_suffix = datetime.datetime.now().strftime("%Y_%m_%d-%H-%M-%S") ```