Package: jij-cimod
cimod : C++ header-only library for a binary quadratic modelCoverage GraphSunburstGridIcicleDocumentsPython DocumentsHow to useYou should only include a headersrc/binary_quadratic_model.hppin your project.ExampleC++#include"src/binary_quadratic_model.hpp"usingnamespacecimod;intmain(){// Set linear biases and quadratic biasesLinear<uint32_t,double>linear{{1,1.0},{2,2.0},{3,3.0},{4,4.0}};Quadratic<uint32_t,double>quadratic{{std::make_pair(1,2),12.0},{std::make_pair(1,3),13.0},{std::make_pair(1,4),14.0},{std::make_pair(2,3),23.0},{std::make_pair(2,4),24.0},{std::make_pair(3,4),34.0}};// Set offsetdoubleoffset=0.0;// Set variable typeVartypevartype=Vartype::BINARY;// Create a BinaryQuadraticModel instanceBinaryQuadraticModel<uint32_t,double,cimod::Dense>bqm(linear,quadratic,offset,vartype);//linear terms -> bqm.get_linear()//quadratic terms -> bqm.get_quadratic()return0;}Pythonimportcimodimportdimod# Set linear biases and quadratic biaseslinear={1:1.0,2:2.0,3:3.0,4:4.0}quadratic={(1,2):12.0,(1,3):13.0,(1,4):14.0,(2,3):23.0,(2,4):24.0,(3,4):34.0}# Set offsetoffset=0.0# Set variable typevartype=dimod.BINARY# Create a BinaryQuadraticModel instancebqm=cimod.BinaryQuadraticModel(linear,quadratic,offset,vartype)print(bqm.linear)print(bqm.quadratic)For ContributorUsepre-commitfor auto chech before git commit..pre-commit-config.yaml# pipx install pre-commit 
# or 
# pip install pre-commit
pre-commit installInstallvia this directory$python-mpipinstall-vvv.via pip# Binary$pipinstalljij-cimod# From Source$pipinstall--no-binary=jij-cimodjij-cimodTestPython$python-mvenv.venv
$pipinstallpip-tools$pip-compilesetup.cfg
$pip-compiledev-requirements.in
$pip-syncrequirements.txtdev-requirements.txt
$source.venv/bin/activate
$exportCMAKE_BUILD_TYPE=Debug
$pythonsetup.py--force-cmakeinstall--build-typeDebug-GNinja
$pythonsetup.py--build-typeDebugtest$python-mcoveragehtmlC++$mkdirbuild$cmake-DCMAKE_BUILD_TYPE=Debug-S.-Bbuild
$cmake--buildbuild--parallel
$cdbuild
$./tests/cimod_test# Alternatively Use CTest$ctest--extra-verbose--parallel--schedule-randomNeeds: CMake > 3.22, C++17Format$pip-compileformat-requirements.in
$pip-syncformat-requirements.txt$python-misort$python-mblackAggressive Format$python-misort--force-single-line-imports--verbose./cimod
$python-mautoflake--in-place--recursive--remove-all-unused-imports--ignore-init-module-imports--remove-unused-variables./cimod
$python-mautopep8--in-place--aggressive--aggressive--recursive./cimod
$python-misort./cimod
$python-mblack./cimodLint$pip-compilesetup.cfg
$pip-compiledev-requirements.in
$pip-compilelint-requirements.in
$pip-syncrequirements.txtdev-requirements.txtlint-requirements.txt$python-mflake8
$python-mmypy
$python-mpyrightBenchmarkBenchmark codeimportdimodimportcimodimporttimefil=open("benchmark","w")fil.write("N t_dimod t_cimod\n")defbenchmark(N,test_fw):linear={}quadratic={}spin={}# interactionsforiinrange(N):spin[i]=1foreleminrange(N):linear[elem]=2.0*elem;foriinrange(N):forjinrange(i+1,N):ifi!=j:quadratic[(i,j)]=(i+j)/(N)t1=time.time()# initializea=test_fw.BinaryQuadraticModel(linear,quadratic,0,test_fw.BINARY)a.change_vartype(test_fw.SPIN)# calculate energy for 50 times.for_inrange(50):print(a.energy(spin))t2=time.time()returnt2-t1d_arr=[]c_arr=[]forNin[25,50,100,200,300,400,600,800,1000,1600,2000,3200,5000]:print("N{}".format(N))d=benchmark(N,dimod)c=benchmark(N,cimod)print("{}{}{}".format(N,d,c))fil.write("{}{}{}\n".format(N,d,c))Software versionsPackageVersioncimod1.0.3dimod0.9.2ResultLicencesCopyright 2022 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 athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.