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.1.tar.gz
(199.0 kB
view hashes)
Built Distributions
Close
Hashes for jij_cimod-1.2.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 386813e077d2839993e17ce262f638acfc55fca117ba41633242d745f48ca3b9 |
|
MD5 | fc3d4c951226941a3acae1e6f5f79e75 |
|
BLAKE2b-256 | b070a2a856c41eff32ccccb1f24a99d19ee7cdc1f37219a0b655ef7e73542564 |
Close
Hashes for jij_cimod-1.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fd1490e790669ed2de314244f2141639339f95a2bf595c84c19dbdfbcc489f8 |
|
MD5 | a08b613022cf5bb719c3c8b029cc98f7 |
|
BLAKE2b-256 | a994a73be76403d2acae6fbc21d3348eba820071c68467bbaf2fc29039ab6716 |
Close
Hashes for jij_cimod-1.2.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33f643ad2528aea3621b509c2fe2acc72e6e76c38e686798add269ee2cfc1c3e |
|
MD5 | c2a413f5870c498e2fdc19b1acdb8b5b |
|
BLAKE2b-256 | abbe0fee31f1a88f95ecc860f49a60826924fa1748e42be495f718148fce4436 |
Close
Hashes for jij_cimod-1.2.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90156b6ab4daf23f543d66fc32a543a8035d64ed03d513aafc8fc335d2c0c105 |
|
MD5 | a98a36e8d032c0559f2d4341043dc0e3 |
|
BLAKE2b-256 | 95eedc6d408ddc6409dfcc2f5c1e8f26ddf9a61ef8a6cf3f93243618c37d3252 |
Close
Hashes for jij_cimod-1.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 145d7aad5d64cce3ac5ff5f2bbe8bbaff9e73b019de22b0153e8b7b4cbcc4ce0 |
|
MD5 | 8010bdc30be0c1715eaf5c31ff8f4ec3 |
|
BLAKE2b-256 | f12a7ac818057ca99a079f515dafc2e5f0c0141182929eacd34551d819c9d96f |
Close
Hashes for jij_cimod-1.2.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c426379f5b65624495d4cb3b0ba166a0c09629b924692221c8fb0b5ed1ba58eb |
|
MD5 | 392b26b5f773527730df701f8d423661 |
|
BLAKE2b-256 | c75af7732d961ee6e8b4f714bfa15f09f5c95573431c620e71cb0b662a307b0d |
Close
Hashes for jij_cimod-1.2.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f40e658d7a805153b574cebd11b24cf6a2733fa2486871d7d82adcdb532d63a |
|
MD5 | 99550600b5bca67d4798dd846a75ef36 |
|
BLAKE2b-256 | 9d5583734fbbb5d166bbf3adaecb32cd2cf1b16485eacb818d0ed8cd7d32218c |
Close
Hashes for jij_cimod-1.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4a64a7c936244e62c44ca4b421a41611b84ff3d25258fb628e855a6013a736f |
|
MD5 | b63cfd379ea98556e4e7d325c1bce929 |
|
BLAKE2b-256 | 7d57c9f90e996bc586a3a0498f20cd605013b7c178b7f86daebf1a23e234eaa1 |
Close
Hashes for jij_cimod-1.2.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 816d2860603194f916f1c15b3bbd5825a403774c4d276dd40b832b23bc4a4c8e |
|
MD5 | 471014857ca37f11945aec2393730b9c |
|
BLAKE2b-256 | c705e624bf9a183b4287a4f21f8916e593111ffc2884732cf783bec9345ccb63 |