Skip to main content

OMMX adapter for fireopal.solve_qaoa

Reason this release was yanked:

This version is the same as v0.1.0.

Project description

ommx-qctrl-qaoa-adapter

This package provides an adapter that lets you solve OMMX problems with Q-CTRL’s Fire Opal QAOA solver hosted on IBM Quantum.

OMMX (Open Mathematical programming Modeling eXtension) is an open standard for representing mathematical optimisation problems. Modeling once in OMMX lets you evaluate both classical and quantum solvers. Besides this Fire Opal adapter there are adapters for PySCIPOpt, D-Wave, and more:

OMMX also provides utilities to turn constrained models into unconstrained QUBO/HUBO via Instance.to_qubo / Instance.to_hubo. Define your model once; convert only when needed. See the OMMX tutorial for details.

Prerequisites

Before using the adapter you need:

  • Q-CTRL account API key (used to authenticate fireopal)
  • Either:
    • IBM Quantum API token and IBM Quantum instance CRN (to build credentials locally), or
    • A Fire Opal credential bundle you already saved via Q-CTRL tooling

Warning: Running Q-CTRL’s QAOA solver on IBM Quantum hardware consumes credits or usage. Understand the pricing before launching jobs.

Installation

Install from PyPI:

pip install ommx-qctrl-qaoa-adapter

Fire Opal QAOA overview

Fire Opal’s QAOA solver handles unconstrained binary optimisation problems across many combinatorial classes. It supports polynomial cost functions with arbitrary-order terms but requires at least one non-linear term. For the purely linear objectives are rejected to avoid spending quantum resources on trivial cases. See the Fire Opal QAOA solver guide for the detailed criteria. Use Instance.to_qubo / to_hubo to eliminate constraints and ensure quadratic penalties when necessary.

Usage

0. Authenticate your Q-CTRL account using an API key

The link provide how to get the Q-CTRL account and API key. If you already have authenticated the account in the enviroument. you can skip this process.

import fireopal

fireopal.authenticate_qctrl_account(api_key="Q-CTRL API Key")

1. Define your OMMX problem

from ommx.v1 import DecisionVariable, Instance

x0 = DecisionVariable.binary(0)
x1 = DecisionVariable.binary(1)
x2 = DecisionVariable.binary(2)

#Example objective (must include quadratic or higher terms)
objective = x0 + x1 - 2 * x0 * x1 + x1 + x2 - 2 * x1 * x2

# Example constraint: select at most two vertices.
constraint = x0 + x1 + x2 <= 2

instance = Instance.from_components(
    decision_variables=[x0, x1, x2],
    objective=objective,
    constraints=[constraint],
    sense=Instance.MAXIMIZE,
)

# Convert the constrained model to an unconstrained QUBO with a penalty term.
qubo_instance = instance.to_qubo()

Use qubo_instance (or instance.to_hubo(...) if you prefer higher-order penalties) when calling the adapter so Fire Opal receives an unconstrained formulation.

2. Solve with Fire Opal

from ommx_qctrl_qaoa_adapter import OMMXQctrlQAOAAdapter
from fireopal.run_options import IbmRunOptions

IBM_TOKEN = "your_ibm_cloud_token"
IBM_INSTANCE = "crn:v1:..."
BACKEND_NAME = "ibm_device"

run_opts = IbmRunOptions(session_id=None, job_tags=["ommx-demo"])

solution = OMMXQctrlQAOAAdapter.solve(
    ommx_instance=qubo_instance,
    backend_name=BACKEND_NAME,
    ibm_token=IBM_TOKEN,
    ibm_instance=IBM_INSTANCE,
    run_options=run_opts,
)
print("Objective:", solution.objective)
print("Assignments:", solution.state.entries)

Decode previously solved jobs

If you already ran fireopal.solve_qaoa elsewhere, you can reconstruct the OMMX solution from the below:

from ommx_qctrl_qaoa_adapter import OMMXQctrlQAOAAdapter

adapter = OMMXQctrlQAOAAdapter(qubo_instance)

fire_opal_result = {
    "solution_bitstring": "101",
    "solution_bitstring_cost": -2.0,
    "variables_to_bitstring_index_map": {"x_0": 0, "x_1": 1, "x_2": 2},
}

solution = adapter.decode(fire_opal_result)
print("Objective:", solution.objective)

Environment variables example

Before running the OMMXQctrlQAOAAdapter you can set:

export IBM_QUANTUM_TOKEN=...
export IBM_QUANTUM_INSTANCE=...

Error handling

OMMXQctrlQAOAAdapterError is raised when:

  • No decision variables, or non-binary variables are present
  • Constraints remain (Fire Opal only supports unconstrained problems)
  • The objective contains only linear terms
  • Fire Opal job fails (check IBM Quantum dashboard)
  • Credentials are missing or invalid

Development

Install dev dependencies via uv:

uv sync --all-extras

Run tests:

uv run pytest

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ommx_qctrl_qaoa_adapter-0.1.1.dev0.tar.gz (82.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ommx_qctrl_qaoa_adapter-0.1.1.dev0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file ommx_qctrl_qaoa_adapter-0.1.1.dev0.tar.gz.

File metadata

  • Download URL: ommx_qctrl_qaoa_adapter-0.1.1.dev0.tar.gz
  • Upload date:
  • Size: 82.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ommx_qctrl_qaoa_adapter-0.1.1.dev0.tar.gz
Algorithm Hash digest
SHA256 d8cd839ded06893a0b2cc731828f803ac112d2438f2c8ebccbb1769a958d4554
MD5 5b2a2fc5513e257f28de630f38581c94
BLAKE2b-256 efc8b16b7a65f45ec55c2ac226d99cfb3090a2d030ff32980dfce4be734a3ddd

See more details on using hashes here.

File details

Details for the file ommx_qctrl_qaoa_adapter-0.1.1.dev0-py3-none-any.whl.

File metadata

  • Download URL: ommx_qctrl_qaoa_adapter-0.1.1.dev0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for ommx_qctrl_qaoa_adapter-0.1.1.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf8114efefa0045ef618a6e9c5f1b285e10b16a17d656137c04b321fbe6497f9
MD5 4b41d7a835009507ca426dabfa1fa25b
BLAKE2b-256 d8a3c797c980dce6ce7fe6e26e4c7fcecca1d64603f1f0d621a16cd947915e9b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page