GithubHelp home page GithubHelp logo

openjij / openjij Goto Github PK

View Code? Open in Web Editor NEW
94.0 12.0 24.0 48.86 MB

OpenJij : Framework for the Ising model and QUBO.

Home Page: https://www.openjij.org/

License: Apache License 2.0

CMake 5.40% Python 26.77% C++ 63.98% Cuda 1.65% Shell 0.12% Makefile 0.10% HTML 0.84% CSS 1.13%
cmake optimization benchmarking quantum-computing quantum-mechanics quantum-annealing simulated-annealing python

openjij's Introduction

OpenJij : Framework for the Ising model and QUBO.

PyPI version shields.io PyPI pyversions PyPI implementation PyPI format PyPI license PyPI download month Downloads

CPP Test Python Test Build Documentation CodeQL Codacy Badge Maintainability codecov

Coverage Graph

Sunburst Grid Icicle
  • python >= 3.8
  • (optional) gcc >= 7.0.0
  • (optional) cmake >= 3.22
  • (optional) Ninja

OpenJij Website

Change IMPORT

  • OpenJij >= v0.5.0

    import openjij.cxxjij
  • OpenJij <= v0.4.9

    import cxxjij
  • Documents

  • C++ Docs

install

install via pip

Note: (2023/08/09) GPGPU algorithms will no longer be supported.

# Binary
$ pip install openjij 
# From Source
$ pip install --no-binary=openjij openjij

install via pip from source codes

To install OpenJij from source codes, please install CMake first then install OpenJij.

cmake setup

If you want to use setup.py instead of PIP, You will need to install CMake>=3.22.
We are Highly recommended install CMake via PYPI.

$ pip install -U cmake

Make sure the enviroment path for CMake is set correctly.

install OpenJij

$ pip install --no-binary=openjij openjij

install from github repository

$ git clone [email protected]:OpenJij/OpenJij.git
$ cd openjij
$ python -m pip install -vvv .

For Contributor

Use pre-commit for auto chech before git commit. .pre-commit-config.yaml

# pipx install pre-commit 
# or 
# pip install pre-commit
pre-commit install

Test

Python

$ python -m venv .venv
$ . .venv/bin/activate
$ pip install pip-tools 
$ pip-compile setup.cfg
$ pip-compile dev-requirements.in
$ pip-sync requirements.txt dev-requirements.txt
$ source .venv/bin/activate
$ export CMAKE_BUILD_TYPE=Debug
$ python setup.py --force-cmake install --build-type Debug -G Ninja
$ python setup.py --build-type Debug test 
$ python -m coverage html

C++

$ mkdir build 
$ cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build
$ cmake --build build --parallel
$ cd build
$ ./tests/cxxjij_test
# Alternatively  Use CTest 
$ ctest --extra-verbose --parallel --schedule-random

Needs: CMake > 3.22, C++17

  • Format
$ pip-compile format-requirements.in
$ pip-sync format-requirements.txt
$ python -m isort 
$ python -m black 
  • Aggressive Format
$ python -m isort --force-single-line-imports --verbose ./openjij
$ python -m autoflake --in-place --recursive --remove-all-unused-imports --ignore-init-module-imports --remove-unused-variables ./openjij
$ python -m autopep8 --in-place --aggressive --aggressive  --recursive ./openjij
$ python -m isort ./openjij
$ python -m black ./openjij
  • Lint
$ pip-compile setup.cfg
$ pip-compile dev-requirements.in
$ pip-compile lint-requirements.in
$ pip-sync requirements.txt dev-requirements.txt lint-requirements.txt
$ python -m flake8
$ python -m mypy
$ python -m pyright

Python Documentation

Use Juyter Book for build documentation.
With KaTeX
Need: Graphviz

$ pip-compile setup.cfg
$ pip-compile build-requirements.in
$ pip-compile doc-requirements.in
$ pip-sync requirements.txt build-requirements.txt doc-requirements.txt

Please place your document to docs/tutorialeither markdown or jupyter notebook style.

$ pip install -vvv .
$ jupyter-book build docs --all

How to use

Python example

import openjij as oj
sampler = oj.SASampler()
response = sampler.sample_ising(h={0: -1}, J={(0,1): -1})
response.states
# [[1,1]]

# with indices
response = sampler.sample_ising(h={'a': -1}, J={('a','b'): 1})
[{index: s for index, s in zip(response.indices, state)} for state in response.states]
# [{'b': -1, 'a': 1}]

Community

About us

This product is maintained by Jij Inc.

Please visit our website for more information! https://www.j-ij.com/

Licences

Copyright 2023 Jij Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0  

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

openjij's People

Contributors

29rou avatar dependabot[bot] avatar github-actions[bot] avatar github-nakasho avatar j-i-k-o avatar jacomichi avatar k-suzuki-jij avatar kumagaimasahito avatar mei-maruo avatar mrcdr avatar mullzhang avatar ny57 avatar shibukazu avatar shitaro avatar tatsuyagoto-jij avatar y-yu avatar yuyamashiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openjij's Issues

SASamplerにおけるstep_num, iterationによる異常な振る舞い

Title

SASamplerにおけるstep_num, iterationによる異常な振る舞い

Comment

SASamplerに古い引数であるstep_numをiterationの値を代入することができました。
その場合に、計算結果のベンチマークをとると正しい値になりません。

Execution environment

macOS 10.14

Reproduction procedure

  1. OpenJij ver. 0.0.11をimport
  2. SASampler(num_sweeps, num_reads)とSASampler(step_num, iteration)を比較したときに発生

Should do

openjij/sampler/sa_sampler.pyの__init__の修正

Undefined behavior with an odd number of trotter slices

Odd number of trotter slices results in undefined behavior (all spin values are set to 0).

chimera = cj.graph.Chimera(2,2, init_val=-0.5)
method = cj.method.ChimeraGPUQuantum(chimera, num_trotter_slices=3)
method.simulated_quantum_annealing(10.0, 0.1, 10.0, 5, 10)
res = method.get_spins()
for r in res:
  print(r)
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

GPU Windows CUDA Complie error

Error output

parse<openjij::FloatTy
pe>,true>(pybind11::module &,const std::string &,const std::string &)' のリファレンスを確認してください [C:\Users\winya\source\repos\OpenJij\OpenJij\build\openjij\cxxjij.vcxproj]
     ライブラリ C:/Users/winya/source/repos/OpenJij/OpenJij/build/openjij/Debug/cxxjij.lib とオブジェクト C:/Users/winya/source/repos/OpenJij/OpenJij/build/openjij/Debug/cxxjij.exp を作成
  中
cxxjij_chimera_gpu_kernel_static.lib(kernel.obj) : error LNK2001: 外部シンボル "__cudaRegisterLinkedBinary_41_tmpxft_00004298_00000000_7_kernel_cpp1_ii_fd013a99" は未解決で
す。 [C:\User
s\winya\source\repos\OpenJij\OpenJij\build\openjij\cxxjij.vcxproj]
C:\Users\winya\source\repos\OpenJij\OpenJij\build\openjij\Debug\cxxjij.cp37-win_amd64.pyd : fatal error LNK1120: 1 件の未解決の外部参照 [C:\Users\winya\source\repos\OpenJij\OpenJij\b
uild\openjij\cxxjij.vcxproj]
  Building Custom Rule C:/Users/winya/source/repos/OpenJij/OpenJij/src/system/CMakeLists.txt
  Compiling CUDA source file ..\..\..\src\system\gpu\chimera_cuda\kernel.cu...

Two changes in openjij/declare.hpp

  • There is no namespace in declare.hpp. It is recommended to add them (openjij::).
  • add Classical/TransverseField schedule in declare.hpp

fix gen_spin

fix gen_spin for controling seeds

#include "graph.h"
#include <cassert>
#include <random>

namespace openjij {
	namespace graph {
		const Spins Graph::gen_spin(bool random_initialize) const{
                // TODO: gen_spin(bool random_initialize, int seed) const{
			//generate spin array
			Spins ret_spin(num_spins);
			if(random_initialize){
				std::random_device rd;
				auto mt = std::mt19937(rd());
				std::uniform_int_distribution<> unif(0, 1);
				for(auto& elem : ret_spin){
					elem = 2*unif(mt)-1;
				}
			}
			else{
                         ...

don't work benchmark function with PyQUBO

pyquboの出力だとラベルが文字列なのでopenjijに投げた時にstateに入るスピンの順番が意図せずバラバラになる。benchmark 関数では state in correct_states (stateが配列)で評価しているので、順番が異なるとダメ。辞書型でラベル対応させて比べないと状態があっているのがどうかを評価できない。

Fix Graph module in python wrapper

In the current version, the GPU system must be initialized with the Graph type with the suffix "GPU".
GPU system should be initialized with the Graph type the same as CPU.
before
system = S.make_xxx_ising_gpu(self.dense.gen_spin(self.seed_for_spin), self.denseGPU)
after
system = S.make_xxx_ising_gpu(self.dense.gen_spin(self.seed_for_spin), self.dense)

Graph class should be deprecated.

OpenJij is now replacing Graph class with BQM class with c++ implementation.
All constructors in the system should be initialized with the BQM class.

Unnatural behavior about vartype.

The following conditional expression should be true but is false.

import openjij as oj
model = oj.BinaryQuadraticModel({}, {(0,1):1}, "SPIN")
model.vartype == model.get_vartype()
False

It seems that model.vartype is openjij.Vartype.SPIN but model.get_vartype() returns cxxcimod.SPIN.
Both must be openjij.Vartype.SPIN

Environment
ProductName: macOS
ProductVersion: 12.0.1
BuildVersion: 21A559
Python 3.9.8 (main, Nov 10 2021, 03:55:42)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin

support windows environment

Currently, OpenJij does not support the windows environment.
We need to remake cmake for the Windows environment.

Integrated test for OpenJij

  • To ensure the latest version of OpenJij works correctly, integrated test for OpenJij (e.g., running all scripts in OpenJijTutorial) triggered just before release should be configured.

sample_qubo does not work

Describe the bug
SASampler().sample_qubo does not work

To Reproduce
Steps to reproduce the behavior:

import openjij as oj
res = oj.SASampler().sample_qubo({(0, 1): -1})

Error

TypeError: make_BinaryQuadraticModel() missing 1 required positional argument: 'sparse'
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
----> 1 oj.SASampler().sample_qubo({(0, 1): -2}, sparse=True)
 in sample_qubo(self, Q, **parameters)
    230             :class:`openjij.sampler.response.Response`: results
    231         """
--> 232         bqm = openjij.BinaryQuadraticModel.from_qubo(Q)
    233         return self.sample(bqm, **parameters)
    234 

in <lambda>(Q, offset, **kwargs)
    174 #classmethods
    175 BinaryQuadraticModel.from_qubo = \
--> 176         lambda Q, offset=0.0, **kwargs: make_BinaryQuadraticModel({}, Q).from_qubo(Q, offset, **kwargs)
    177 
    178 BinaryQuadraticModel.from_ising = \

/openjij/model/model.py in make_BinaryQuadraticModel(linear, quadratic)
     46     """
     47 
---> 48     class BinaryQuadraticModel(cimod.make_BinaryQuadraticModel(linear, quadratic)):
     49         """Represents Binary quadratic model. 
     50            Indices are listed in self.indices.

TypeError: make_BinaryQuadraticModel() missing 1 required positional argument: 'sparse'

Expected behavior
sample_qubo should be working.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: macOS 11.5.2
  • Enviroment: jupyter notebook
  • Python: 3.9.6
  • Version: OpenJij (0.0.1), dimod (0.9.15), jij-cimod (1.2.3)

Additional context
Add any other context about the problem here.

`setup.py test` is deprecated

python setup.py test outputs the following warning:

running test
WARNING: Testing via this command is deprecated and will be removed in a future version. Users looking for a generic test entry point independent of test runner are encouraged to use tox.

We should replace the test with an alternative one (e.g., tox?) shortly.

openjij.GPUChimeraSASampler does not work

Following python code raises the error (shape mismatching in NumPy)

a = oj.GPUChimeraSASampler(unit_num_L = 2)
a.sample_ising(h={0: 0.1, 1: 0.4}, J={(2,5): 0.3})

error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/ssd/workspace/linux/workspace/Jij/openjij/OpenJij/openjij/sampler/chimera_gpu/gpu_sa_sampler.py", line 113, in sample_ising
    return self._sampling(model, beta_min, beta_max,
  File "/mnt/ssd/workspace/linux/workspace/Jij/openjij/OpenJij/openjij/sampler/sa_sampler.py", line 204, in _sampling
    response = self._cxxjij_sampling(
  File "/mnt/ssd/workspace/linux/workspace/Jij/openjij/OpenJij/openjij/sampler/sampler.py", line 120, in _cxxjij_sampling
    sampling_time = exec_sampling()
  File "/mnt/ssd/workspace/linux/workspace/Jij/openjij/OpenJij/openjij/sampler/sampler.py", line 27, in wrapper
    func(*args, **kargs)
  File "/mnt/ssd/workspace/linux/workspace/Jij/openjij/OpenJij/openjij/sampler/sampler.py", line 113, in exec_sampling
    energies.append(model.calc_energy(result_state))
  File "/mnt/ssd/workspace/linux/workspace/Jij/openjij/OpenJij/openjij/model/model.py", line 150, in calc_energy
    energy = (np.dot(_state, np.dot(int_mat, _state)) -
  File "<__array_function__ internals>", line 5, in dot
ValueError: shapes (4,4) and (32,) not aligned: 4 (dim 1) != 32 (dim 0)

This error may occur since the Chimera graph with 2 * 2 * 8 spins is interpreted to Binary Quadratic Model with four spins when evaluating calc_energy inside Python implementation of OpenJij.

Error in CSQASampler()

Describe the bug
CSQASampler() causes the NoneType-related error.

To Reproduce

>>> import openjij as oj
>>> h = {0: -1, 1: -1, 2: 1, 3: 1}
>>> J = {(0, 1): -1, (3, 4): -1}
>>> sampler = oj.CSQASampler()
>>> res = sampler.sample_ising(h, J)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/openjij/sampler/csqa_sampler.py", line 103, in sample_ising
    self._annealing_schedule_setting(
  File "/usr/local/lib/python3.9/site-packages/openjij/sampler/sqa_sampler.py", line 228, in _annealing_schedule_setting
    self._schedule, beta_gamma = quartic_ising_schedule(
  File "/usr/local/lib/python3.9/site-packages/openjij/sampler/sqa_sampler.py", line 270, in quartic_ising_schedule
    s = np.linspace(0, 1, num_sweeps)
  File "<__array_function__ internals>", line 5, in linspace
  File "/usr/local/lib/python3.9/site-packages/numpy/core/function_base.py", line 120, in linspace
    num = operator.index(num)
TypeError: 'NoneType' object cannot be interpreted as an integer

Expected behavior

  • No error outputs

Environment (please complete the following information):

  • OS: Arch Linux
  • Version: Python 3.9.6

Additional context

How can I install "openjij" ?

I can't install openjij by pip.

$pip install openjij
Could not find a version that satisfies the requirement openjij (from versions: )
No matching distribution found for openjij

beta_min and beta_max must be consistent with changing vartype

The cooling schedule does not seem to be consistent with changing vartype

import openjij as oj
model = oj.BinaryPolynomialModel({(0,1):-1}, "SPIN")
res = oj.SASampler().sample_hubo(model.to_hising(), "SPIN")
res.info['schedule']
{'beta_max': 2.302585092994046, 'beta_min': 0.34657359027997264, 'num_sweeps': 1000}

res = oj.SASampler().sample_hubo(model.to_hubo(), "BINARY")
res.info['schedule']
{'beta_max': 1.5350567286626973, 'beta_min': 0.11552453009332421, 'num_sweeps': 1000}

Above two cases should have the same cooling schedule.
This inconsistency also occurs in sample_ising and sample_qubo.

setting binary `initial_state` results in wrong solution

Describe the bug
setting initial_state keyword of sample_qubo with binary variables (0, 1) results in weird answer.

To Reproduce

>>> import openjij as oj
>>> a = oj.SASampler()
>>> a.sample_qubo(Q={(2, 2): -68.55, (0, 2): 0.1, (1, 3): 0.1, (3, 4): 0.1, (1, 4): 0.1, (4, 4): -66.55, (2, 3): 0.1, (1, 1): -69.55, (0, 0): -70.55, (0, 4): 0.1, (0, 3): 0.1, (2, 4): 0.1, (0, 1): 0.1, (3, 3): -67.55, (1, 2): 0.1}, num_sweeps=1000, initial_state=[1,1,0,1,1])
Response(rec.array([([1, 1, 0, 1, 1], -273.6, 1)],
          dtype=[('sample', 'i1', (5,)), ('energy', '<f8'), ('num_occurrences', '<i8')]), Variables([0, 1, 2, 3, 4]), {'system': [], 'sampling_time': 1059.5160019875038, 'execution_time': 900.4790008475538, 'list_exec_times': array([900.47900085]), 'schedule': {'beta_max': 184.20680743952366, 'beta_min': 0.01964981376498782, 'num_sweeps': 1000}}, 'BINARY')

Expected behavior
Result binary array should be [1,1,1,1,1]

Additional context
This error comes from the missing conversion of the binary initial_state array to spin array.

Inconsistency on the number of spins in core python interface

Following the tutorial on classical ising model (https://openjij.github.io/OpenJijTutorial/build/html/ja/A003-LargeScaleMC.html),
I executed this program (using openjij==0.1.1 and numpy==1.19.1):

import numpy as np
import cxxjij.graph as G
import cxxjij.system as S

N = 100
graph = G.Dense(N)

mu, sigma = 0, 1

for i in range(N):
    for j in range(N):
        # to avoid a large Jij value, normalize in 1/N
        graph[i,j] = 0 if i == j else np.random.normal()/N

for i in range(N):
    graph[i] = np.random.normal()/N

spin = graph.gen_spin()
mysystem = S.make_classical_ising(spin, graph)

Then, I noticed that the number of spins generated at random does not match the number of spins the system has.

print(len(spin), mysystem.num_spins, graph.size())
>>> 100 100 100

print(mysystem.spin.shape)
>>> (101,)

can access over column and row at chimera graph

import cxxjij as cj
L = 3
chimera = cj.graph.Chimera(1, L)
print(chimera[2, 2, 0], chimera[1, 4, 0])

0, 0

設定したcolumn と row よりも大きい column と row にアクセスしてもエラーが出ない。
エラー出した方がよい。

Add SingleBinaryFlip for QUBO

  • Conversion from QUBO problem to Ising problem is a time-consuming task. Implementing SingleBinayFlip may accelerate the calc speed.

C++ test messages

If USE_TEST is not set, C++ test will not be executed, but the following command
python setup.py test
seems to raise Error like

Python tests complete, now running C++ tests...

build/lib.macosx-11-x86_64-3.9
make: *** No rule to make target `cxxjij_test'.  Stop.
/bin/sh: ./tests/cxxjij_test: No such file or directory

This appears to be an error message, so it would be better to replace the proper message.

double-precison on GPU interface

In a current version of the library, GPU-based algorithms can be used only with a single-precision floating-point type. To use GPU-based algorithms with double precision, one should add compile and linker options (e.g. nvcc -arch sm_60) in the CMake file.
(Note that this compile option does not work on previous versions of GPU devices.)

openjij.SASampler().sample_XXX should not change the default parameters

Current specifications are

import openjij as oj
sampler = oj.SASampler()
res = sampler.sample_ising({}, {(0,1):-1}, num_sweeps=10)
res.info['schedule']
-->'num_sweeps': 10

res = sampler.sample_ising({}, {(0,1):-1})
res.info['schedule']
-->'num_sweeps': 10

But that should be like

import openjij as oj
sampler = oj.SASampler()
res = sampler.sample_ising({}, {(0,1):-1}, num_sweeps=10)
res.info['schedule']
-->'num_sweeps': 10

res = sampler.sample_ising({}, {(0,1):-1})
res.info['schedule']
-->'num_sweeps': 1000

Note that the default value of num_sweeps is 1000.

Make the classical Hamiltonian time-dependent.

Now the total Hamiltonian in SQA is
$$H=H_0 + \Gamma V_{TF}$$

However, I think the following Hamiltonian is good.
$$H = s H_0 + (1-s)\Gamma V_{TF}$$
where s=t/\tau

The reason is that if the first term is not dependent on time, in reverse annealing, the spatial direction of the classical system is fixed.
Similarly, if Gamma_max is not sufficiently large with respect to the classical term, it is likely to be addicted to the local solution in the first Hamiltonian.

vartype in polynomial system cannot be represented.

The following code

import cxxjij
model = cxxjij.graph.Polynomial(3)
model[0,1,2] = 1
sys = cxxjij.system.make_classical_ising_polynomial([1,1,1], model, "SPIN")
sys.vartype

raises

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Unable to convert function return value to a Python type! The signature was
        (self: cxxjij.system.ClassicalIsing_Polynomial) -> cimod::Vartype

Environment:

  • OS: macOS 12.0.1
  • Version python3.9

Strange behavior of annealing time

Describe the bug
When the same problem is annealed by different num_sweeps, even though num_sweep is set smaller, the annealing time may be long.

import openjij as oj

N = 30
h = {0: -10}
J = {(i, i+1): 1 for i in range(N-1)}

num_reads = 10

for num_sweeps in [25, 50]:
    sampler = oj.SASampler(num_sweeps=num_sweeps, num_reads=num_reads)
    response = sampler.sample_ising(h, J)
    t = response.info["execution_time"]
    print(f"t(num_sweeps={num_sweeps}) = {t}")

t(num_sweeps=25) = 88.32270978018641
t(num_sweeps=50) = 58.8218797929585

Expected behavior

  • t(num_sweeps=25) < t(num_sweeps=50)

Environment (please complete the following information):

  • OS: ubuntu18.04
  • Version python 3.9.6

delta energy calculation

It is better to calculate the dE first and only update the dE when flipping spins so that the energy difference is calculated less often.

About cooling schedule

res = oj.SASampler().sample_ising({}, {(0,1):-1, (0,2):+1})
res.info['schedule']
{'beta_max': 4.605170185988092, 'beta_min': 0.34657359027997264, 'num_sweeps': 1000}

Then we multiply the interaction by two.

res = oj.SASampler().sample_ising({}, {(0,1):-2, (0,2):+2})
res.info['schedule']
{'beta_max': 4.605170185988092, 'beta_min': 0.17328679513998632, 'num_sweeps': 1000}

beta_max must be 2.30258509299 (half of the first beta_max) ?

ContinuousTimeQuantumIsing solver failed under gcc 10

Summary

python setup.py test command fails under the latest version of gcc.

Versions

gcc-libs ((before)9.3.0-1 -> (after)10.1.0-2)
gcc ((before)9.3.0-1 -> (after)10.1.0-2)
gcc-fortran ((before)9.3.0-1 -> (after)10.1.0-2)

Outputs

test_benchmark (tests.test_utils.TestUtils) ... ok
test_str_key_success_prob (tests.test_utils.TestUtils) ... ok
test_var_type (tests.test_utils.TestUtils) ... ok
test_csqa (tests.test_sampler.TestSamplers) ... FAIL
test_sa (tests.test_sampler.TestSamplers) ... ok
test_sqa (tests.test_sampler.TestSamplers) ... ok
test_bqm (tests.test_model.ModelTest) ... ok
test_bqm_calc_energy (tests.test_model.ModelTest) ... ok
test_bqm_constructor (tests.test_model.ModelTest) ... ok
test_chimera (tests.test_model.ModelTest) ... ok
test_chimera_converter (tests.test_model.ModelTest) ... ok
test_energy_consistency (tests.test_model.ModelTest) ... ok
test_get_chimera_graph (tests.test_model.ModelTest) ... ok
test_interaction_matrix (tests.test_model.ModelTest) ... ok
test_ising_dict (tests.test_model.ModelTest) ... ok
test_king_graph (tests.test_model.ModelTest) ... ok
test_transfer_to_cxxjij (tests.test_model.ModelTest) ... ok
test_variable_type (tests.test_model.VariableTypeTest) ... ok
test_ContinuousTimeSwendsenWang_ContinuousTimeIsing_Sparse (tests.test.CXXTest) ... FAIL
test_SingleSpinFlip_ClassicalIsing_Dense (tests.test.CXXTest) ... ok
test_SingleSpinFlip_ClassicalIsing_Sparse (tests.test.CXXTest) ... ok
test_SingleSpinFlip_TransverseIsing_Dense (tests.test.CXXTest) ... ok
test_SingleSpinFlip_TransverseIsing_Sparse (tests.test.CXXTest) ... ok
test_SwendsenWang_ClassicalIsing_Sparse (tests.test.CXXTest) ... ok
test_hubo_sampling (tests.test_hubo.HUBOTest) ... ok

======================================================================
FAIL: test_csqa (tests.test_sampler.TestSamplers)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jiko/workspace/Jij/openjij/OpenJij/tests/test_sampler.py", line 120, in test_csqa
    self.samplers(sampler,
  File "/home/jiko/workspace/Jij/openjij/OpenJij/tests/test_sampler.py", line 48, in samplers
    self._test_response(res, self.e_q, self.ground_q)
  File "/home/jiko/workspace/Jij/openjij/OpenJij/tests/test_sampler.py", line 53, in _test_response
    self.assertListEqual(s_g, list(res.states[0]))
AssertionError: Lists differ: [1, 1, 0, 0, 0] != [1, 1, 0, 0, 1]

First differing element 4:
0
1

- [1, 1, 0, 0, 0]
?              ^

+ [1, 1, 0, 0, 1]
?              ^


======================================================================
FAIL: test_ContinuousTimeSwendsenWang_ContinuousTimeIsing_Sparse (tests.test.CXXTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jiko/workspace/Jij/openjij/OpenJij/tests/test.py", line 291, in test_ContinuousTimeSwendsenWang_ContinuousTimeIsing_Sparse
    self.assertTrue(self.true_groundstate == result_spin)
AssertionError: False is not true

----------------------------------------------------------------------
Ran 25 tests in 4.749s

Chimera graph symmetry

The connection should have symmetry. However, Chimera graph not has symmetry.

import cxxjij as cj
chimera = cj.graph.Chimera(2,2)
chimera[0,0,4, cj.graph.ChimeraDir.PLUS_C] = 2
print(chimera[0,0,4, cj.graph.ChimeraDir.PLUS_C], chimera[1,0,4, cj.graph.ChimeraDir.MINUS_C])

2, 0 # these two value should be same from symmetry.

build fails on AArch64, Fedora 33

[jw@cn06 openjij]$ sudo python3 setup.py install --verbose
running install
running bdist_egg
running egg_info
writing openjij.egg-info/PKG-INFO
writing dependency_links to openjij.egg-info/dependency_links.txt
writing requirements to openjij.egg-info/requires.txt
writing top-level names to openjij.egg-info/top_level.txt
reading manifest file 'openjij.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '.cmake'
warning: no files found matching 'FetchContent/
.cmake.in'
writing manifest file 'openjij.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-aarch64/egg
running install_lib
running build_py
running build_ext
-- GCC detected, adding compile flags
-- No CUDA support
-- USE_OMP = Yes
-- USE_CUDA = No
-- USE_TEST = Yes
-- Fetch googletest for C++ testing
[ 11%] Performing download step (git clone) for 'googletest-populate'
Cloning into 'googletest-src'...
fatal: unable to access 'https://github.com/google/googletest.git/': Could not resolve host: github.com
Cloning into 'googletest-src'...
fatal: unable to access 'https://github.com/google/googletest.git/': Could not resolve host: github.com
Cloning into 'googletest-src'...
fatal: unable to access 'https://github.com/google/googletest.git/': Could not resolve host: github.com
-- Had to git clone more than once:
3 times.
CMake Error at googletest-subbuild/googletest-populate-prefix/tmp/googletest-populate-gitclone.cmake:31 (message):
Failed to clone repository: 'https://github.com/google/googletest.git'

gmake[2]: *** [CMakeFiles/googletest-populate.dir/build.make:111: googletest-populate-prefix/src/googletest-populate-stamp/googletest-populate-download] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/googletest-populate.dir/all] Error 2
gmake: *** [Makefile:103: all] Error 2

CMake Error at /usr/share/cmake/Modules/FetchContent.cmake:987 (message):
Build step for googletest failed: 2
Call Stack (most recent call first):
/usr/share/cmake/Modules/FetchContent.cmake:1082:EVAL:2 (__FetchContent_directPopulate)
/usr/share/cmake/Modules/FetchContent.cmake:1082 (cmake_language)
external/googletest.cmake:13 (FetchContent_Populate)
CMakeLists.txt:73 (include)

-- Configuring incomplete, errors occurred!
See also "/data/jw/openjij/build/temp.linux-aarch64-3.9/CMakeFiles/CMakeOutput.log".
See also "/data/jw/openjij/build/temp.linux-aarch64-3.9/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
File "/data/jw/openjij/setup.py", line 122, in
setup(
File "/usr/lib/python3.9/site-packages/setuptools/init.py", line 165, in setup
return distutils.core.setup(**attrs)
File "/usr/lib64/python3.9/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib64/python3.9/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr/lib64/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3.9/site-packages/setuptools/command/install.py", line 67, in run
self.do_egg_install()
File "/usr/lib/python3.9/site-packages/setuptools/command/install.py", line 109, in do_egg_install
self.run_command('bdist_egg')
File "/usr/lib64/python3.9/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib64/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3.9/site-packages/setuptools/command/bdist_egg.py", line 174, in run
cmd = self.call_command('install_lib', warn_dir=0)
File "/usr/lib/python3.9/site-packages/setuptools/command/bdist_egg.py", line 160, in call_command
self.run_command(cmdname)
File "/usr/lib64/python3.9/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib64/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/lib/python3.9/site-packages/setuptools/command/install_lib.py", line 11, in run
self.build()
File "/usr/lib64/python3.9/distutils/command/install_lib.py", line 107, in build
self.run_command('build_ext')
File "/usr/lib64/python3.9/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib64/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/data/jw/openjij/setup.py", line 43, in run
self.build_extension(ext)
File "/data/jw/openjij/setup.py", line 73, in build_extension
subprocess.check_call(['cmake', ext.sourcedir] +
File "/usr/lib64/python3.9/subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/data/jw/openjij', '-DUSE_TEST=Yes', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/data/jw/openjij/build/lib.linux-aarch64-3.9', '-DPYTHON_EXECUTABLE=/usr/bin/python3', '-DCMAKE_BUILD_TYPE=Release']' returned non-zero exit status 1.
[jw@cn06 openjij]$

iteration depend previous annealing

iteration で複数回 annealing したときにスピンの状態を初期化していないので、前のアニーリングの結果に引きずられているっぽい。ちゃんと初期化しないといけない。
c++側で初期化メソッドを作るか、python側でiterationのたびにcxxjij.graph.Graphインスタンスを再生性しないいけない。

pip install error : Ubuntu

Error message

Collecting openjij
  Downloading https://files.pythonhosted.org/packages/64/f2/ac9fd9380e7464c78b5e66f278b70e083fa3395e57c6c521b90f8b7c313e/openjij-0.0.1.0.tar.gz
Requirement already satisfied: numpy in /usr/local/lib/python3.6/site-packages (from openjij) (1.15.4)
Building wheels for collected packages: openjij
  Building wheel for openjij (setup.py) ... error
  Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-m3y_dlos/openjij/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-_n2vxo_n --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/openjij
  copying openjij/sampler.py -> build/lib.linux-x86_64-3.6/openjij
  copying openjij/model.py -> build/lib.linux-x86_64-3.6/openjij
  copying openjij/utils.py -> build/lib.linux-x86_64-3.6/openjij
  copying openjij/__init__.py -> build/lib.linux-x86_64-3.6/openjij
  running build_ext
  <__main__.CMakeExtension('cxxjij') at 0x7ff642d3a358> cxxjij
  -- The C compiler identification is GNU 6.3.0
  -- The CXX compiler identification is GNU 6.3.0
  -- Check for working C compiler: /usr/bin/cc
  -- Check for working C compiler: /usr/bin/cc -- works
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Check for working CXX compiler: /usr/bin/c++
  -- Check for working CXX compiler: /usr/bin/c++ -- works
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Fetch googletest for C++ testing
  -- Found PythonInterp: /usr/local/bin/python (found version "3.6.8")
  -- Looking for pthread.h
  -- Looking for pthread.h - found
  -- Looking for pthread_create
  -- Looking for pthread_create - not found
  -- Check if compiler accepts -pthread
  -- Check if compiler accepts -pthread - yes
  -- Found Threads: TRUE
  -- Fetch pybind11 for python-binding
  -- Found PythonLibs: /usr/local/lib/libpython3.6m.so
  -- pybind11 v2.2.4
  -- Looking for a CUDA compiler
  -- Looking for a CUDA compiler - NOTFOUND
  -- No CUDA support
  -- USE_OMP = No
  -- USE_CUDA = No
  -- USE_TEST = No
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /tmp/pip-install-m3y_dlos/openjij/build/temp.linux-x86_64-3.6
  Scanning dependencies of target algorithm_static
  Scanning dependencies of target graph_static
  [  7%] Building CXX object src/algorithm/CMakeFiles/algorithm_static.dir/sa.cpp.o
  [ 14%] Building CXX object src/graph/CMakeFiles/graph_static.dir/graph.cpp.o
  [ 21%] Building CXX object src/algorithm/CMakeFiles/algorithm_static.dir/sqa.cpp.o
  [ 28%] Linking CXX static library libalgorithm_static.a
  [ 35%] Building CXX object src/graph/CMakeFiles/graph_static.dir/dense.cpp.o
  [ 35%] Built target algorithm_static
  [ 42%] Building CXX object src/graph/CMakeFiles/graph_static.dir/sparse.cpp.o
  [ 50%] Building CXX object src/graph/CMakeFiles/graph_static.dir/square.cpp.o
  [ 57%] Building CXX object src/graph/CMakeFiles/graph_static.dir/chimera.cpp.o
  [ 64%] Linking CXX static library libgraph_static.a
  [ 64%] Built target graph_static
  Scanning dependencies of target method_static
  [ 71%] Building CXX object src/method/CMakeFiles/method_static.dir/classical_ising.cpp.o
  [ 78%] Building CXX object src/method/CMakeFiles/method_static.dir/quantum_ising.cpp.o
  [ 85%] Linking CXX static library libmethod_static.a
  [ 85%] Built target method_static
  Scanning dependencies of target cxxjij
  [ 92%] Building CXX object openjij/CMakeFiles/cxxjij.dir/main.cpp.o
  [100%] Linking CXX shared module ../../lib.linux-x86_64-3.6/cxxjij.cpython-36m-x86_64-linux-gnu.so
  /usr/bin/ld: ../src/graph/libgraph_static.a(graph.cpp.o): relocation R_X86_64_PC32 against symbol `_ZNSt23mersenne_twister_engineImLm32ELm624ELm397ELm31ELm2567483615ELm11ELm4294967295ELm7ELm2636928640ELm15ELm4022730752ELm18ELm1812433253EEclEv' can not be used when making a shared object; recompile with -fPIC
  /usr/bin/ld: final link failed: Bad value
  collect2: error: ld returned 1 exit status
  openjij/CMakeFiles/cxxjij.dir/build.make:88: recipe for target '../lib.linux-x86_64-3.6/cxxjij.cpython-36m-x86_64-linux-gnu.so' failed
  make[3]: *** [../lib.linux-x86_64-3.6/cxxjij.cpython-36m-x86_64-linux-gnu.so] Error 1
  CMakeFiles/Makefile2:662: recipe for target 'openjij/CMakeFiles/cxxjij.dir/all' failed
  make[2]: *** [openjij/CMakeFiles/cxxjij.dir/all] Error 2
  CMakeFiles/Makefile2:706: recipe for target 'openjij/CMakeFiles/python.dir/rule' failed
  make[1]: *** [openjij/CMakeFiles/python.dir/rule] Error 2
  Makefile:320: recipe for target 'python' failed
  make: *** [python] Error 2
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-m3y_dlos/openjij/setup.py", line 109, in <module>
      zip_safe=False
    File "/usr/local/lib/python3.6/site-packages/setuptools/__init__.py", line 143, in setup
      return distutils.core.setup(**attrs)
    File "/usr/local/lib/python3.6/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/usr/local/lib/python3.6/distutils/dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "/usr/local/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/usr/local/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 188, in run
      self.run_command('build')
    File "/usr/local/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/local/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/usr/local/lib/python3.6/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/usr/local/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/local/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/tmp/pip-install-m3y_dlos/openjij/setup.py", line 34, in run
      self.build_extension(ext)
    File "/tmp/pip-install-m3y_dlos/openjij/setup.py", line 62, in build_extension
      subprocess.check_call(['cmake', '--build', '.', '--target', 'python'] + build_args, cwd=self.build_temp)
    File "/usr/local/lib/python3.6/subprocess.py", line 311, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'python', '--config', 'Release', '--', '-j2']' returned non-zero exit status 2.

  ----------------------------------------
  Failed building wheel for openjij
  Running setup.py clean for openjij
Failed to build openjij

Build wheel automation

It is recommended to enable build automation by using Travis CI for the convenience.
FYI Attached is the example of the pull request in qulacs library. Please see the rewritten .travis.yml in the request.

qulacs/qulacs#233

Use Tox

WARNING: Testing via this command is deprecated and will be removed in a future version. Users looking for a generic test entry point independent of test runner are encouraged to use tox.

I can't compile "benchmark.py"

I can't compile "benchmark.py".
When I try following command, I got some error.
$python benchmark.py

File "benchmark.py", line 2, in <module> import matplotlib.pyplot as plt File "~/.pyenv/versions/3.7.0/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2374, in <module> switch_backend(rcParams["backend"]) File "~/.pyenv/versions/3.7.0/lib/python3.7/site-packages/matplotlib/pyplot.py", line 207, in switch_backend backend_mod = importlib.import_module(backend_name) File "~/.pyenv/versions/3.7.0/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "~/.pyenv/versions/3.7.0/lib/python3.7/site-packages/matplotlib/backends/backend_macosx.py", line 14, in <module> from matplotlib.backends import _macosx ImportError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.