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 Distribution
jij_cimod-1.2.0.tar.gz
(199.1 kB
view hashes)
Built Distributions
Close
Hashes for jij_cimod-1.2.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8337f4b0790edb5e926b44dee168df13cba37e5ff1083ba297a2f328b30282a |
|
MD5 | 4d1f92446c45c1315d435b4afc7b8bd1 |
|
BLAKE2b-256 | 9779486bc7e3850a1466baaee8c11edafeb74cb3d4097befbc665a4b07a3d3dc |
Close
Hashes for jij_cimod-1.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edc1106ede263c95fb153ebc4c5082630dbe0904d2aca44ebbc7820ad4d394c4 |
|
MD5 | b1dee40daa4fa1d8ad2d2e2e0fe41935 |
|
BLAKE2b-256 | e07e2d05bc42e7bec6d9f41cb8256579f8f918de686f81454936311f8944c70a |
Close
Hashes for jij_cimod-1.2.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 211a1092a1a6acbc0006e6d11ab86260ac904c7d52058fa1b19a5e3138dc7c93 |
|
MD5 | e292d81aeff105f73fd4262067663ce1 |
|
BLAKE2b-256 | 13510ceb92b6cdc0c4ae39d443bbe69103ae14bebd09e2dadc3090e71b0db3fe |
Close
Hashes for jij_cimod-1.2.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b98b7c0740bb3578c8ff8a003cdb1b5b3901f3712c7fc45300722c18d8de6623 |
|
MD5 | c9804d80ff2e536f579e489f72e6bd30 |
|
BLAKE2b-256 | aadf4c244e26f1d6686a50b9d6eecbce315fe9a45f76721e7311654b01f9e22a |
Close
Hashes for jij_cimod-1.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd52b53dec51bcbbcfed5b48e9e9bbb0c91ad4e995f22473f2011b09b3e455ca |
|
MD5 | e4b8ed81197325702df98f317cfcb186 |
|
BLAKE2b-256 | fc2f984875ebd73ba2e932246f647e5b228dbcabff64ebe3c2f5007b087c6e89 |
Close
Hashes for jij_cimod-1.2.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71080af1d38d87ce7feb156718c7f913b3195dd368cd2ec5a1583e2745b1acac |
|
MD5 | e13127aa31bcfafae341eb2bd5aa2f8f |
|
BLAKE2b-256 | de7d261643a498cf0a532bce6754f29f27b0117aeace1b05f58910457c0c76df |
Close
Hashes for jij_cimod-1.2.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7ced2b257549091881cd0ab7bb64086115e36adc7ed21f6773c70840214d45d |
|
MD5 | 6b5eefab0d0f8e9e0dc4b63976ea6411 |
|
BLAKE2b-256 | 91086a502287bd21bf103ca72a2c1b491909a3770213a59c922e0b93ad508145 |
Close
Hashes for jij_cimod-1.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5940e5748b6b5f46f63c194e514fe02b0b8cb6ef4144f532fab09903951fa72 |
|
MD5 | 9b0aa1a156b815a6de0d0ad1d56670e3 |
|
BLAKE2b-256 | a966565c540b6fb810a693a35e4cf14749ce1ec01e18eb10ba4f65dab222bfa4 |
Close
Hashes for jij_cimod-1.2.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31a337a1df278bb893a7e2a59cd233284b013a5fad97f8378ce9e63215af5f85 |
|
MD5 | 019cc9e8e1ea9a8ab1f6746119598778 |
|
BLAKE2b-256 | 135966adb9aaad78451061a628d2f8d19ff85c08d60dc9b7a397e9b263622bd1 |