Welcome to OpenJij’s documentation!#
OpenJij : Framework for the Ising model and QUBO.#
Introduction#
Github repository OpenJij Website
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#
- openjij
- Subpackages
- openjij.model
- Submodules
- openjij.model.chimera_model
- openjij.model.king_graph
- openjij.model.model
- Functions
- Module Contents
BinaryPolynomialModel()
BinaryQuadraticModel()
vartype
linear
quadratic
offset
num_variables
variables
bqm_from_ising()
bqm_from_numpy_matrix()
bqm_from_qubo()
make_BinaryPolynomialModel()
make_BinaryPolynomialModel_from_JSON()
make_BinaryPolynomialModel_from_hising()
make_BinaryPolynomialModel_from_hubo()
make_BinaryQuadraticModel()
make_BinaryQuadraticModel_from_JSON()
- Functions
- Package Contents
BinaryPolynomialModel()
BinaryQuadraticModel()
vartype
linear
quadratic
offset
num_variables
variables
bqm_from_numpy_matrix()
make_BinaryPolynomialModel()
make_BinaryPolynomialModel_from_JSON()
make_BinaryPolynomialModel_from_hising()
make_BinaryPolynomialModel_from_hubo()
make_BinaryQuadraticModel()
- Submodules
- openjij.sampler
- Submodules
- openjij.sampler.base_sa_sample_hubo
- openjij.sampler.csqa_sampler
- openjij.sampler.response
- Classes
- Module Contents
Response
Response.aggregate()
Response.append_variables()
Response.change_vartype()
Response.copy()
Response.data()
Response.done()
Response.filter()
Response.from_future()
Response.from_samples()
Response.from_samples_bqm()
Response.from_samples_cqm()
Response.from_serializable()
Response.lowest()
Response.relabel_variables()
Response.resolve()
Response.samples()
Response.slice()
Response.to_pandas_dataframe()
Response.to_serializable()
Response.truncate()
Response.data_vectors
Response.energies
Response.first
Response.indices
Response.info
Response.min_samples
Response.record
Response.states
Response.variables
Response.vartype
- openjij.sampler.sa_sampler
- openjij.sampler.sampler
- openjij.sampler.sqa_sampler
- Classes
- Functions
- Package Contents
CSQASampler
Response
Response.aggregate()
Response.append_variables()
Response.change_vartype()
Response.copy()
Response.data()
Response.done()
Response.filter()
Response.from_future()
Response.from_samples()
Response.from_samples_bqm()
Response.from_samples_cqm()
Response.from_serializable()
Response.lowest()
Response.relabel_variables()
Response.resolve()
Response.samples()
Response.slice()
Response.to_pandas_dataframe()
Response.to_serializable()
Response.truncate()
Response.data_vectors
Response.energies
Response.first
Response.indices
Response.info
Response.min_samples
Response.record
Response.states
Response.variables
Response.vartype
SASampler
SQASampler
measure_time()
- Submodules
- openjij.utils
- openjij.model
- Submodules
- Attributes
- Classes
- Functions
- Package Contents
CSQASampler
Response
Response.aggregate()
Response.append_variables()
Response.change_vartype()
Response.copy()
Response.data()
Response.done()
Response.filter()
Response.from_future()
Response.from_samples()
Response.from_samples_bqm()
Response.from_samples_cqm()
Response.from_serializable()
Response.lowest()
Response.relabel_variables()
Response.resolve()
Response.samples()
Response.slice()
Response.to_pandas_dataframe()
Response.to_serializable()
Response.truncate()
Response.data_vectors
Response.energies
Response.first
Response.indices
Response.info
Response.min_samples
Response.record
Response.states
Response.variables
Response.vartype
SASampler
SQASampler
BinaryPolynomialModel()
BinaryQuadraticModel()
vartype
linear
quadratic
offset
num_variables
variables
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における相互作用行列の保持の仕方
- 最適化への適用例
- 機械学習への適用例
- 物理シミュレーション
- 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