Skip to main content

OMMX adapter for fireopal.solve_qaoa

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.0.1.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.0.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file ommx_qctrl_qaoa_adapter-0.0.1.tar.gz.

File metadata

  • Download URL: ommx_qctrl_qaoa_adapter-0.0.1.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.0.1.tar.gz
Algorithm Hash digest
SHA256 1e6f46fc1f43b22e21595273a58d5be09bccd281e10f665bc4bd47ec10a844a4
MD5 25a57cc8d90dcd95472f262d6cd591e7
BLAKE2b-256 5319502d89b44c621552ecb45d7274191f1b966b521630524f613feb36cc5de0

See more details on using hashes here.

File details

Details for the file ommx_qctrl_qaoa_adapter-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ommx_qctrl_qaoa_adapter-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0aff6c9b12cf7da7c2a2b1486034e3f012c6f94b89b407b26ce64a7d72776e0e
MD5 e8bdce47b4afe0ce26d3eebd12c52eda
BLAKE2b-256 960d787601d9848e09e4bfa8adf2dcb26f1f83be6aad945746cf5123edc63059

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