OMMXを使用してSCIPで解く

OMMXを使用してSCIPで解く#

このチュートリアルでは、このデータセットが量子アルゴリズムではないSCIP(ommx-pyscipopt-adapter)とどのようにシームレスに使用できるかを見ていきます。しかし、OMMX形式の美しい点の一つは、実際には量子アルゴリズムでも古典的アルゴリズムでもシームレスに採用できることです。

# Install ommx-pyscipopt-adapter as needed.
# !pip install "ommx-pyscipopt-adapter"
import ommx_pyscipopt_adapter

from ommx_quantum_benchmarks.qoblib import Labs

データの読み込み#

まず、このライブラリを使用して1つのデータを読み込みます。代表的な例として、Labsデータセットの"quadratic_unconstrained"モデルの"labs003"インスタンスを使用します。インスタンス、モデル、またはデータセットを自由に変更してください。利用可能なインスタンスについては、qoblibページを参照してください。

# See the available models and instances.
dataset = Labs()

for model_name, instance_names in dataset.available_instances.items():
    print(f"Model: {model_name}")
    for instance_name in instance_names[:5]:  # Show only first 5 instances
        print(f"  Instance: {instance_name}")
Model: integer
  Instance: labs002
  Instance: labs003
  Instance: labs004
  Instance: labs005
  Instance: labs006
Model: quadratic_unconstrained
  Instance: labs002
  Instance: labs003
  Instance: labs004
  Instance: labs005
  Instance: labs006
# Load a specific instance.
model_name = "quadratic_unconstrained"
instance_name = "labs003"
(instance, solution) = dataset(model_name, instance_name)

print(f"Instance: {instance}")
print(f"Given Solution: {solution}")
[2026-06-16 08:14:16] 🚀 Starting experiment 'qoblib_v2'
[2026-06-16 08:14:16]   ├─ 📊 Environment: OS: Linux 6.17.0-1018-azure, CPU: AMD EPYC 9V74 80-Core Processor (4 cores), Memory: 15.6 GB, Python: 3.11.15
[2026-06-16 08:14:16]   ├─ 📊 Environment Information
[2026-06-16 08:14:16]       ├─ OS: Linux 6.17.0-1018-azure
[2026-06-16 08:14:16]       ├─ Platform: Linux-6.17.0-1018-azure-x86_64-with-glibc2.39
[2026-06-16 08:14:16]       ├─ CPU: AMD EPYC 9V74 80-Core Processor (4 cores)
[2026-06-16 08:14:16]       ├─ Memory: 15.6 GB
[2026-06-16 08:14:16]       ├─ Architecture: x86_64
[2026-06-16 08:14:16]       ├─ Python: 3.11.15
[2026-06-16 08:14:16]       ├─ Virtual Environment: /home/runner/work/OmmxQuantumBenchmarks/OmmxQuantumBenchmarks/.venv
[2026-06-16 08:14:16]       ├─ Key Package Versions:
Instance: Instance(raw=<builtins.Instance object at 0x7f5980266c30>, annotations={'org.ommx.v1.instance.authors': 'Thorsten Koch,David E. Bernal Neira,Ying Chen,Giorgio Cortiana,Daniel J. Egger,Raoul Heese,Narendra N. Hegade,Alejandro Gomez Cadavid,Rhea Huang,Toshinari Itoko,Thomas Kleinert,Pedro Maciel Xavier,Naeimeh Mohseni,Jhon A. Montanez-Barrera,Koji Nakano,Giacomo Nannicini,Corey O’Meara,Justin Pauckert,Manuel Proissl,Anurag Ramesh,Maximilian Schicker,Noriaki Shimada,Mitsuharu Takeori,Victor Valls,David Van Bulck,Stefan Woerner,Christa Zoufal', 'org.ommx.v1.instance.constraints': '0', 'org.ommx.v1.instance.title': 'labs003', 'org.ommx.qoblib.url': 'https://git.zib.de/qopt/qoblib-quantum-optimization-benchmarking-library/-/tree/main/02-labs?ref_type=heads', 'org.minto.name': 'labs003', 'org.ommx.v1.instance.license': 'CC BY 4.0', 'org.minto.space': 'experiment', 'org.ommx.v1.instance.variables': '9', 'org.ommx.v1.instance.dataset': 'Low Autocorrelation Binary Sequences (LABS)', 'org.minto.storage': 'instances'})
Given Solution: Solution(raw=<builtins.Solution object at 0x7f597bffc8d0>, annotations={'org.ommx.v1.solution.instance': 'sha256:11da1b5ffe097d37e5e16ab3710eb2da0cb565f8980123e7e36912e2fda32192', 'org.minto.name': 'labs003', 'org.minto.space': 'run', 'org.ommx.qoblib.authors': 'Thorsten Koch, David E. Bernal Neira, Ying Chen, Giorgio Cortiana, Daniel J. Egger, Raoul Heese, Narendra N. Hegade, Alejandro Gomez Cadavid, Rhea Huang, Toshinari Itoko, Thomas Kleinert, Pedro Maciel Xavier, Naeimeh Mohseni, Jhon A. Montanez-Barrera, Koji Nakano, Giacomo Nannicini, Corey O’Meara, Justin Pauckert, Manuel Proissl, Anurag Ramesh, Maximilian Schicker, Noriaki Shimada, Mitsuharu Takeori, Victor Valls, David Van Bulck, Stefan Woerner, Christa Zoufal', 'org.minto.storage': 'solutions', 'org.minto.run_id': '0'})

SCIPを使用して解く#

# Solve with SCIP.
obtained_solution = ommx_pyscipopt_adapter.OMMXPySCIPOptAdapter.solve(instance)

# Compare the results.
print(f"Given solution: {solution.objective=}, {obtained_solution.feasible=}")
print(f"Obtained solution: {obtained_solution.objective=}, {obtained_solution.feasible=}")
Given solution: solution.objective=1.0, obtained_solution.feasible=True
Obtained solution: obtained_solution.objective=1.0, obtained_solution.feasible=True