Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

QCI Optimization with QCIOpt.jl (Julia)

Maintained by the JuliaQUBO organization
SECQUOIA  ·  PSR Energy

Open In Colab

This notebook is the Julia counterpart to notebooks_py/6-QCi_python.ipynb. It teaches the QUBO workflow supported by QCIOpt.jl through JuMP, while identifying the continuous and constrained eqc-models examples that do not have direct Julia equivalents.

The default path is deterministic, credential-free, and service-free. QCI cloud submission is a separate explicit opt-in. QCIOpt.jl is a community wrapper and is not officially supported by Quantum Computing Inc.

Setup

The notebook uses the repository’s shared Julia project. The first code cell locates the checkout in a local Jupyter session or clones it in a native Julia Colab runtime, then delegates environment setup to the common bootstrap.

Local installation: clone this repository, run uv sync --locked --group docs, start Jupyter from the checkout, and select the Julia kernel. The bootstrap activates and instantiates notebooks_jl/Project.toml; do not add packages in notebook cells.

Google Colab

Select a Julia runtime, run the bootstrap cell once, and continue in order. Package installation belongs to the shared notebooks_jl environment; there are no notebook-local Pkg.add calls.

Notebook Cell
Notebook Cell

Learning objectives

By the end of this notebook you will be able to:

  1. construct a binary quadratic JuMP model with Model(QCIOpt.Optimizer);

  2. establish a small QUBO’s optimum by independent enumeration before any provider call;

  3. configure the QCI device, sample count, and token through supported optimizer attributes;

  4. gate cloud execution on both an explicit opt-in and QCI_TOKEN;

  5. enumerate live results and independently check their binary values and reported energies; and

  6. distinguish direct QCIOpt workflows from Python-only or manually reformulated eqc-models examples.

Prerequisites

Prior notebooks: Notebook 2’s QUBO and Ising introduction is recommended, but the exact example below is self-contained.

  • Basic Julia and JuMP syntax.

  • The distinction between a constrained optimization model and a QUBO, whose constraints must already be represented in a quadratic objective.

  • For the optional cloud section only: a QCI account, an API token stored in QCI_TOKEN, and permission to submit to the selected device.

No token is needed for setup, model construction, enumeration, exercises, or default verification.

QCIOpt URL-only revision: 30a6074fdd5bd75c3f1cf965329edd01c67e63fe

A small QUBO with an independent exact check

We will minimize

E(x)=(∑i=13xi−1)2,xi∈{0,1}.E(x) = \left(\sum_{i=1}^{3} x_i - 1\right)^2,\qquad x_i\in\{0,1\}.

The square penalizes selecting zero, two, or three items. Exactly one selected item has energy zero. The instance is deliberately small enough to enumerate, so the reference result does not depend on QCIOpt or a cloud response. The binary variables and objective energies are dimensionless quantities [-].

A JuMP Model ├ solver: QCI Optimizer (dirac-3) ├ objective_sense: MIN_SENSE │ └ objective_function_type: QuadExpr ├ num_variables: 3 ├ num_constraints: 3 │ └ VariableRef in MOI.ZeroOne: 3 └ Names registered in the model └ :x
Independent exact optimum: energy = 0
Optimal bit vectors: 
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]

The three optima are the three one-hot vectors. This exact table is the contract for the optional live response: a returned bit vector must be binary, and its independently recomputed energy must agree with the provider value. The table does not predict which optimum will be sampled most often.

QCIOpt attributes and optional cloud execution

The pinned QCIOpt revision exposes DeviceType() on the JuMP optimizer. Its current optimizer implementation represents the sample count and API token as MathOptInterface raw attributes named num_samples and api_token.

The upstream README shows QCIOpt.NumberOfReads(), but that spelling is not exported by the pinned optimizer revision. The additive QCIOpt.DiracSampler interface instead calls its count NumberOfSamples(). Here we stay with the issue’s requested Model(QCIOpt.Optimizer) interface and use the attributes its source and tests actually support.

Configured DIRAC-3 with 10 requested samples; no job has been submitted.

Explicit cloud guard

Cloud execution requires both:

  • QUBONOTEBOOKS_QCI_ENABLE_CLOUD=1, an explicit acknowledgement that the next cell may submit a provider job; and

  • a nonempty QCI_TOKEN supplied through the process environment or an approved hosted-notebook secret store.

The default verification target forces the opt-in off. A separate live target also sets QUBONOTEBOOKS_QCI_REQUIRE_CLOUD=1, so it fails if submission did not occur. Never paste a token into a cell or save it in notebook output.

QCI cloud execution requested; credentials will be checked in the submission cell.
Validated 3 returned solutions; best energy = 0.0.
  result 1: bits=[0, 1, 0], energy=0.0, multiplicity=5
  result 2: bits=[0, 0, 1], energy=0.0, multiplicity=3
  result 3: bits=[1, 0, 0], energy=0.0, multiplicity=2

Python-to-Julia feature map

The Python notebook uses eqc-models, while QCIOpt is a JuMP/MOI wrapper. Similar provider branding does not make the modeling surfaces interchangeable.

Python Notebook 6 workflowQCIOpt.jl statusJulia treatment here
Continuous constrained Dirac-3 modelPython-onlyThe reviewed QCIOpt optimizer supports binary/integer variable domains, not the Python continuous constrained API.
Bounded integer quadratic objective on Dirac-3Direct for supported quadratic JuMP objectivesUse integer variables with bounds and DeviceType() == "dirac-3"; higher-degree nonlinear objectives are not claimed.
QUBO through DIRAC-3DirectUse binary JuMP variables and a quadratic objective, as in this notebook.
Constrained linear integer model converted to QUBORequires manual penalty reformulationDerive and validate the penalty model before submission; QCIOpt does not perform the Python notebook’s automatic conversion.
Explicit constrained polynomial modelPython-only as shownQCIOpt has no direct equivalent to the eqc-models constrained-polynomial wrapper; a QUBO-compatible case may be manually reformulated, but unsupported constraints are not simulated.

This boundary is intentional: the notebook preserves the learning objective of modeling, submission, decoding, and validation without pretending unsupported API parity.

Reading an optional live result responsibly

A returned minimum on this three-variable exercise demonstrates only that a sample contained an exact optimum. It is not evidence of quantum advantage, solver superiority, or production-scale performance. Provider queues and device behavior can vary. Keep live validation focused on binary values, independently recomputed energies, and multiplicities—not account details, opaque identifiers, or unsanitized provider metadata.

Practice checkpoints

Each exercise remains credential-free.

Notebook Cell
Four-variable one-hot optimum: 0 with 4 states.
Notebook Cell
device=dirac-3, samples=10; attribute setup itself did not call optimize!.
Notebook Cell
The guard states are skipped, blocked, and ready, respectively.

Summary

Learning objectives met:

  • Built a binary quadratic model with Model(QCIOpt.Optimizer) without contacting QCI.

  • Established the exact energy and optimal states by independent enumeration.

  • Configured the current supported device and sample-count attributes.

  • Gated token injection and cloud submission behind explicit environment controls.

  • Added result decoding and independent energy checks for the optional live path.

  • Mapped direct, manually reformulated, and Python-only feature boundaries.

Next steps: change the one-hot model, recompute its exact reference table, and only then consider the opt-in live target. For constrained applications, derive and test the penalty formulation independently before submitting it.

Further reading:

  • Review the pinned QCIOpt source and offline tests to track its current JuMP contract.

  • Continue with Notebook 7 for three canonical QUBO formulations and exhaustive validation patterns.