C++ library for a binary quadratic model
Project description
cimod : C++ header-only library for a binary quadratic model
How to use
You should only include a header src/binary_quadratic_model.hpp
in your project.
Example
C++
#include "src/binary_quadratic_model.hpp"
using namespace cimod;
int main()
{
// Set linear biases and quadratic biases
Linear<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 offset
double offset = 0.0;
// Set variable type
Vartype vartype = Vartype::BINARY;
// Create a BinaryQuadraticModel instance
BinaryQuadraticModel<uint32_t, double> bqm(linear, quadratic, offset, vartype);
//linear terms -> bqm.get_linear()
//quadratic terms -> bqm.get_quadratic()
return 0;
}
Python
import cimod
import dimod
# Set linear biases and quadratic biases
linear = {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 offset
offset = 0.0
# Set variable type
vartype = dimod.BINARY
# Create a BinaryQuadraticModel instance
bqm = cimod.BinaryQuadraticModel(linear, quadratic, offset, vartype)
print(bqm.linear)
print(bqm.quadratic)
Install
via this directory
$ python setup.py install
via pip
$ pip install jij-cimod
Benchmark
Benchmark code
import dimod
import cimod
import time
fil = open("benchmark", "w")
fil.write("N t_dimod t_cimod\n")
def benchmark(N, test_fw):
linear = {}
quadratic = {}
spin = {}
# interactions
for i in range(N):
spin[i] = 1
for elem in range(N):
linear[elem] = 2.0*elem;
for i in range(N):
for j in range(i+1, N):
if i != j:
quadratic[(i,j)] = (i+j)/(N)
t1 = time.time()
# initialize
a = test_fw.BinaryQuadraticModel(linear, quadratic, 0, test_fw.BINARY)
a.change_vartype(test_fw.SPIN)
# calculate energy for 50 times.
for _ in range(50):
print(a.energy(spin))
t2 = time.time()
return t2-t1
d_arr = []
c_arr = []
for N in [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 versions
Package | Version |
---|---|
cimod | 1.0.3 |
dimod | 0.9.2 |
Result
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
Close
Hashes for jij_cimod-1.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3e8eb69c464e70a0b779d107a9ba6f5ab36f8faf0f89e43487a4962ac0e86b4 |
|
MD5 | cb9f6e34aff47a77e7cac5f7961c70bf |
|
BLAKE2b-256 | 6ff41b3408ece889703fd6e8fe6cff33b0cb7bcfabcfc5742350b79d857de7c6 |
Close
Hashes for jij_cimod-1.1.0-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca18638c3713050c0919c8c5876dc9c0bb37e7ce91f4f48ae43850ec6b2ca21b |
|
MD5 | 30b100e05330bc47aa20bcb409af3949 |
|
BLAKE2b-256 | daea85007cd189f5936e5b69c8e1f6a22d7840ff6ac9d3e3a4f186b9f76cab72 |
Close
Hashes for jij_cimod-1.1.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f888050bbf6204e293c16affa6d02d1301b16b07eac084b620916b808273342 |
|
MD5 | fb5033b80d3d9edfef7c4d4948e61d52 |
|
BLAKE2b-256 | fb2bc463bef91083ca9411d1075506de3f96869104b8a2bb85b68eaed2ac1804 |
Close
Hashes for jij_cimod-1.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdd179b6056854cf0aff5e6333f7acdf2d0974b60654c05dc8eb06d492ecfb6f |
|
MD5 | 9d014ccffdc36def75f320ef482fcedc |
|
BLAKE2b-256 | 12110c3297661968a05637c63a8cf1a09fc2f5fbbb554148c421dbce80ad7fe9 |
Close
Hashes for jij_cimod-1.1.0-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75e9ce241cb28b4c0493746a38fa5f65073aef270b7afb551ce20875d1c5df24 |
|
MD5 | 8112e12d0ea348eac0577e76e040bf5b |
|
BLAKE2b-256 | 3119723a2d8c65b5fd5cd17f46555f7e2c8c6ed6fe682eb0f6f0e90fa561a7d6 |
Close
Hashes for jij_cimod-1.1.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2c6095ccb4af12c9746558f242bf82a626bb19db6c803783623f0e53ee81f55 |
|
MD5 | f0892694fb836e32cb780314e5d65d33 |
|
BLAKE2b-256 | 9ad6008762d7582a80343b65972eb901d68c0f877f6c33fa7072500fe19887d2 |
Close
Hashes for jij_cimod-1.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e136e0bc3a55746035ac4a44a17f9f237a904122ae4d09ac19e9fd1d671e4ac |
|
MD5 | 750ce23c5917c0bbc33e3e82aa5ea436 |
|
BLAKE2b-256 | af3542277df34524b7b2cfd14ad447e0eda412f3f7c509390c7afbb30aae3f9b |
Close
Hashes for jij_cimod-1.1.0-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2620fea65165cbd42a22ff16191288682a89783d68486da618c995a77c541172 |
|
MD5 | 7824d6e5ae0951a99aeb7ed2d858c519 |
|
BLAKE2b-256 | 849724a0306bb990d938ec012a047482eb8f0fd7263a79392f305c13bb4bdbd8 |
Close
Hashes for jij_cimod-1.1.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9161cc6f3ab5ae0bc020e17ef49caee9a8fdede69322339a8295b8919ee5fa6f |
|
MD5 | 5a2242c02fe2bece40d39caea07fcc52 |
|
BLAKE2b-256 | 3d23131a817b3ba498c9eea7eb93ec3a0377622e775d9793c52425feb51187ff |