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, cimod::Dense> 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 Distribution
jij_cimod-1.2.2.tar.gz
(199.0 kB
view hashes)
Built Distributions
Close
Hashes for jij_cimod-1.2.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6878bf8803e67e3c7f0eecd71c8b8d82414f2b61391d30f905576d0215b8d6ef |
|
MD5 | e649ce060ace090d64c7cc1fb5a8d07b |
|
BLAKE2b-256 | f8e1d48dcda497390885140cefb04658cec4e2b699d720ce23e38babcfaf03c5 |
Close
Hashes for jij_cimod-1.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51435aa1c7f8c107bc8d20eceb3c14c34956623626ed49b7a2b130d6df00884b |
|
MD5 | 7701a5dee79cefd027d2ce99087ac0da |
|
BLAKE2b-256 | 79d929e012ddde1bdd9334a12ffc0142aeb31be62d07ce6a91ce0bf739708929 |
Close
Hashes for jij_cimod-1.2.2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68f5a5b833d180ea2f627f7eacfdccdb854b00f632bbf803a54af4709358b664 |
|
MD5 | a374478d671c9b1a1684af911d8871ed |
|
BLAKE2b-256 | 3ef682216be1eabec2c61a6d3f274bbccf3c626e1b9460ae3bd5414043eaf71f |
Close
Hashes for jij_cimod-1.2.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe2055a23778278c36473f6b38784de343a0d6ffd615c64c22786d99de12673f |
|
MD5 | 1a5114c2050cc2d92904c9e8c9be39eb |
|
BLAKE2b-256 | e246a7adad28bab8073bce57d0a370dd05434869fc34d3f799b655d8dd1683ca |
Close
Hashes for jij_cimod-1.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82c378268289978fb33a1eec5f38fd0decef556bc186ea11bea500053db16184 |
|
MD5 | 6689c109cd6993e82291015881e27fe9 |
|
BLAKE2b-256 | d32f9edc43194b1744f623dc08b0c19ad9865ac564bb532eeed2ee4ac6cd756a |
Close
Hashes for jij_cimod-1.2.2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8929ca9abe69dffb182fc5326c5e0926be9876d6eaf634efbf816eae877f72a |
|
MD5 | 92985244f4a43273bdbaf6d892f6f43c |
|
BLAKE2b-256 | 12e5af754e7f2b13c7b48a2293523b0806a0055455e7cfbe20ff2c9553bd48c4 |
Close
Hashes for jij_cimod-1.2.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e73ee1b53d0b352cbafce3b6db87a705bfa4c6e2a3924578258a6d677e2b766 |
|
MD5 | 90f0e58a4006880dd6eca6f692c8b3b1 |
|
BLAKE2b-256 | 83612e78f6d9d51237b0387c14e6d2e0639a288025db68ff31d19a205434401e |
Close
Hashes for jij_cimod-1.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c523c5f7c3868e8c69f89a5d5d5f7784f77d51eeaf38bbd1ef616822bd918085 |
|
MD5 | b3b2fd32442065a4f6d6250be092dcbf |
|
BLAKE2b-256 | 66ae6c582087b95823e8313216ed7c6b2689c5ab428a04676ed782f87e3c74d2 |
Close
Hashes for jij_cimod-1.2.2-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30a61d5ea05a1c410fd78f0d52df1e4f7b7970f9636226d749840f3125aa35f7 |
|
MD5 | a5023f6e591d6950fa6726ea45657a7a |
|
BLAKE2b-256 | 57ec8d14130382c6e1cbc8e469b1530ea1e100fe713c126bad1e44973d2dee55 |