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.3.tar.gz
(199.1 kB
view hashes)
Built Distributions
Close
Hashes for jij_cimod-1.2.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4551aee87a9b1f35072c36f06c714180ba17e1b8430cdffd6836b143f3337d3 |
|
MD5 | 6cd05f4b50b7a531130c9f6e48654462 |
|
BLAKE2b-256 | 4e034d064360edb4db9d9f7768ec958644d98242d644a382819e4a6e6e09fcb8 |
Close
Hashes for jij_cimod-1.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3f50ec13ae97333c9e645de2acccd2689dcc407d479ce5cf4634483aab6dced |
|
MD5 | 751c33e84594caf87bf9e3f7cbc8094b |
|
BLAKE2b-256 | dc431ce9d7fa2c5cba9268f190244a393ca55f6fac1c1acd5bd6872120c12406 |
Close
Hashes for jij_cimod-1.2.3-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 895b30ebfc53d22d2a2bc146ffc123b237c5cfb4dc47b4151ae44cb70c00b71a |
|
MD5 | 3402f5746726897a66e2c03f3d87f2ac |
|
BLAKE2b-256 | fee9937c5fe68e302f5343863d9f7a92e2939c539ef25682a4a43de9f225a0fe |
Close
Hashes for jij_cimod-1.2.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15fa91d214eddae2ece446f3920f3bf8bd8d44e9a483cfbc07445610233090b0 |
|
MD5 | 4d1c3e2adeb557c66f44ea3cb51e7dc7 |
|
BLAKE2b-256 | 05f353b2b973b9f01759b0bceaf29f3924d5b9dedea4bfb2d7f0d2a081af0da1 |
Close
Hashes for jij_cimod-1.2.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85a1afe63e1f658b28d89d06e7c01f03071d304b61273205d7cf7a69a8e0c563 |
|
MD5 | 57bcc9728476021da5e9166e1f6feadd |
|
BLAKE2b-256 | e6566da8be132b01c16d5facd9714a0ffd6422774aad17e1cde7cfd9082604dd |
Close
Hashes for jij_cimod-1.2.3-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0012d624d64155d88c4eb5b074b7f9bd6cb2be540e8e821532cc7c406d299c27 |
|
MD5 | e63ecce705ccbf3d442f54047afa724e |
|
BLAKE2b-256 | 2ff11643f149b310a4107ac2f5233acea3251cd57118518856cbe4dcec72557f |
Close
Hashes for jij_cimod-1.2.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a825f5153a5dfb8b18b96ad530adc012fa6008fb8a6a41cb6b20a05bd4f886a |
|
MD5 | 57950dcc1c8762f403c4ee8219a55a70 |
|
BLAKE2b-256 | 5eb4ce10b0b62f3b25e3097dd3cb2595463393c63ef072363b14de0e1ebc8f4f |
Close
Hashes for jij_cimod-1.2.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 040e79673e57d09dd72b3f603223a807adfe6652aa09e1bf163b5e1020356fce |
|
MD5 | 7b7bf98654b43b28ec453fe70aebb3e1 |
|
BLAKE2b-256 | c50f27bb180f05d2a6e4f3e115b5191b00a126af313e67885863a8502db37b1c |
Close
Hashes for jij_cimod-1.2.3-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 748d6db5b89ee3521ef6616b0a1e4ec4b066d08009ac195895eced594d46cbee |
|
MD5 | 964e1b2bd2929c0522a98af37c8df615 |
|
BLAKE2b-256 | 769073562d0eca7fd885b8c1819942aa91c64dafcf2388ec2b248139956f4aef |