Welcome to OpenJij’s documentation!#
OpenJij : Framework for the Ising model and QUBO.#
Introduction#
This project is still going. If you can help, please join in the OpenJij Slack Community. Then, you can participate in the project, and ask questions.
What is OpenJij ?#
OpenJij is a heuristic optimization library of the Ising model and QUBO. It has a Python interface, therefore it can be easily written in Python, although the core part of the optimization is implemented with C++. Let’s install OpenJij.
Install#
pip#
$ pip install openjij
Minimum sample code#
Simulated annealing (SA)#
for the Ising model#
to get a sample that executed SA 100 times
import openjij as oj
n = 10
h, J = {}, {}
for i in range(n-1):
for j in range(i+1, n):
J[i, j] = -1
sampler = oj.SASampler()
response = sampler.sample_ising(h, J, num_reads=100)
# minimum energy state
print(response.first.sample)
# {0: -1, 1: -1, 2: -1, 3: -1, 4: -1, 5: -1, 6: -1, 7: -1, 8: -1, 9: -1}
# or
# {0: 1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1, 6: 1, 7: 1, 8: 1, 9: 1}
# indices (labels) of state (spins)
print(response.indices)
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Parameters customize#
Customize annealing schedule#
import openjij as oj
n = 10
h, J = {}, {}
for i in range(n-1):
for j in range(i+1, n):
J[i, j] = -1
# customized annealing schedule
# list of [beta, monte carlo steps in beta]
schedule = [
[10, 3],
[ 5, 5],
[0.5, 10]
]
sampler = oj.SASampler()
response = sampler.sample_ising(h, J, schedule=schedule)
print(response)
Higher order model#
If you want to handle higher order model as follows:
use .sample_hubo
HUBO: Higher order unconstraint binary optimization
Sample code#
import openjij as oj
# Only SASampler can handle HUBO.
sampler = oj.SASampler()
# make HUBO
J = {(0,): -1, (0,1): -1, (0,1,2): 1}
response = sampler.sample_hubo(J, vartype="SPIN")
print(response)
# 0 1 2 energy num_oc.
# 0 +1 +1 -1 -3.0 1
# ['SPIN', 1 rows, 1 samples, 3 variables]
response = sampler.sample_hubo(J, vartype="BINARY")
print(response)
# 0 1 2 energy num_oc.
# 0 1 1 0 -2.0 1
# ['BINARY', 1 rows, 1 samples, 3 variables]
Outline#
API Reference
openjij
- Subpackages
openjij.model
- Submodules
openjij.model.chimera_model
openjij.model.king_graph
openjij.model.model
- Module Contents
- Functions
- Module Contents
- Package Contents
- Submodules
openjij.sampler
- Subpackages
- Submodules
openjij.sampler.base_sa_sample_hubo
openjij.sampler.csqa_sampler
openjij.sampler.response
- Module Contents
- Classes
- Response
- data_vectors
- energies
- first
- indices
- info
- min_samples
- record
- states
- variables
- vartype
- aggregate
- append_variables
- change_vartype
- copy
- data
- done
- filter
- from_future
- from_samples
- from_samples_bqm
- from_samples_cqm
- from_serializable
- lowest
- relabel_variables
- resolve
- samples
- slice
- to_pandas_dataframe
- to_serializable
- truncate
- Response
- Classes
- Module Contents
openjij.sampler.sa_sampler
openjij.sampler.sampler
openjij.sampler.sqa_sampler
- Package Contents
- Classes
- Functions
- CSQASampler
- Response
- data_vectors
- energies
- first
- indices
- info
- min_samples
- record
- states
- variables
- vartype
- aggregate
- append_variables
- change_vartype
- copy
- data
- done
- filter
- from_future
- from_samples
- from_samples_bqm
- from_samples_cqm
- from_serializable
- lowest
- relabel_variables
- resolve
- samples
- slice
- to_pandas_dataframe
- to_serializable
- truncate
- SASampler
- SQASampler
- measure_time
openjij.utils
- Submodules
- Package Contents
- Classes
- Functions
- Attributes
- CSQASampler
- Response
- data_vectors
- energies
- first
- indices
- info
- min_samples
- record
- states
- variables
- vartype
- aggregate
- append_variables
- change_vartype
- copy
- data
- done
- filter
- from_future
- from_samples
- from_samples_bqm
- from_samples_cqm
- from_serializable
- lowest
- relabel_variables
- resolve
- samples
- slice
- to_pandas_dataframe
- to_serializable
- truncate
- SASampler
- SQASampler
- BinaryPolynomialModel
- BinaryQuadraticModel
- base_sample_hubo
- cast_vartype
- convert_response
- solver_benchmark
- BINARY
- SPIN
- Vartype
- Subpackages
- openjij.cxxjij
日本語 チュートリアル
- 組合せ最適化とイジング模型
- イジング模型を用いた最適化計算
- OpenJij 入門
- Higher Order Unconstraint Binary Optimization: HUBO
- JijModelingを用いた数理モデルの構築とOpenJijでの最適化計算
- 巡回セールスマン問題
- OpenJijを用いた最適化の実行
- アニーリングアルゴリズムの評価とOpenJijのベンチマーク機能
- OpenJijにおける相互作用行列の保持の仕方
- 最適化への適用例
- 機械学習への適用例
- 物理シミュレーション
English Tutorial
- Introduction: Combinatorial Optimization and the Ising Model
- Optimization Calculations using Ising Model
- Introduction to OpenJij
- HUBO(Higher Order Unconstraint Binary Optimization)
- Mathematical Model Formulation using JijModeling and Optimization with OpenJij
- Traveling Salesman Problem (TSP)
- Performing Optimization using OpenJij
- Annealing Algorithm Evaluation and OpenJij Benchmarking Capabilities
- Sparse/Dense QUBO Matrix in OpenJij
- 6-Machine Learning (QBoost) with Quantum Annealing
- Optimization
- Number Partitioning
- Knapsack Problem
- Graph Coloring Problem
- Clique Cover Problem
- Job Sequencing Problem with Integer Lengths
- Protein Folding Problem
- Portfolio Optimization using Reverse Quantum Annealing
- Introduction
- Portfolio Optimization
- Portfolio Optimization with Reverse Quantum Annealing
- Generation of stock data and implementation of classical algorithms
- Implementation of quantum annealing method using OpenJij
- Concluding remarks
- Appendix A: if the simulation results are not good…
- Appendix B: Executing RQA on the D-Wave machine
- References
- Machine learning
- Physics simulation