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.1.1.tar.gz
(170.4 kB
view hashes)
Built Distributions
Close
Hashes for jij_cimod-1.1.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac57d2ecaf62f8a6fcab299486bed0d7fc03cb313e7572f02dcb865c11e735c6 |
|
MD5 | 02664eeb817feae11cc57c9adfc21732 |
|
BLAKE2b-256 | 25503bcf355f198f6aca0444821103b92d2639ab2fd11dea6e2d2a9501c96d18 |
Close
Hashes for jij_cimod-1.1.1-cp39-cp39-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df9916ca77781cf1d26628d55686338877e631da647c44931ce6ae2d1917c55f |
|
MD5 | c4c7e4dc6ffe1817a93364c3b4f561ae |
|
BLAKE2b-256 | d3a2f648e678c6ff5894ac90a27956e0284287416db7a77da092006e9ca18a3e |
Close
Hashes for jij_cimod-1.1.1-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d39fd5c1063926401302c59fa6ba500470f8e0bfd8de40aba31a02b45b7bd53 |
|
MD5 | 4241b746d86f2e1abbde83868ab40768 |
|
BLAKE2b-256 | 59cb743fedc55c2a9577733fb3e9978dfdad0496ac3abfe17e32c2454eeeea04 |
Close
Hashes for jij_cimod-1.1.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91c7137935bbbff46c372c287adfbc894f4b638ef25942e9e974dc858063bbc7 |
|
MD5 | ad770f725733037c5c5205e7d675c866 |
|
BLAKE2b-256 | 447ab99434463475589e05f3dab2be829d9b288a575da690569bcbbaaaa73d29 |
Close
Hashes for jij_cimod-1.1.1-cp38-cp38-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc18929c89db55bcb8da8fddf2c4bb7b472c79e4b459facbddc914b5dbe1d8e3 |
|
MD5 | 44c4c16effa869071eadfca6e117f17c |
|
BLAKE2b-256 | 31b264f8d30134962e63871cd8d34bbdd1a4c0cd6ce7688bb29dad68347501a2 |
Close
Hashes for jij_cimod-1.1.1-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d448f68565847c69b4316fd7ab590a3bfe76a93a00d1496e831aaa965ea04721 |
|
MD5 | 30aa092ff5ad49bea648e83b861cacfb |
|
BLAKE2b-256 | 350b25299375e143ec904085851c1955e8f35396d385198a7c52b4f18d30a4b3 |
Close
Hashes for jij_cimod-1.1.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 120c5b9490445baa930424c41f2e0d68158b59f2562604916e2a1b97a36a5856 |
|
MD5 | 385740ba4aef54c6d250924049649412 |
|
BLAKE2b-256 | 0e6218259747d7e8c4d96e9c1cfe42bdb25b68ff657becd3338139ec0f2517b9 |
Close
Hashes for jij_cimod-1.1.1-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1bff7a5fd1533f19beef53fb235e784456e7ab197c3ce4b6a5cb3402ad33f3b |
|
MD5 | 52b3a97700a5f34017e79fed1827fad6 |
|
BLAKE2b-256 | 87f72301898fee698ecb926cab647339454a6c2a2c8975c52b2c840173320ccb |
Close
Hashes for jij_cimod-1.1.1-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87b75edeee9a3b7c1cb274eb4c7eb85b6fd43338c593eaab0ee691b0b7e64999 |
|
MD5 | 059c0774dd88a050614eb40064c74cde |
|
BLAKE2b-256 | 31c0bb9f3f4be43d907bba26a2e326b3587844baeee9b237b8b9ae7714ae2dfa |