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 -m pip 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.3.5.tar.gz
(202.6 kB
view hashes)
Built Distributions
Close
Hashes for jij_cimod-1.3.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d021c4e35710cd41efd110f9063b23f2d98934e6d7cd8b423b2431921a80694 |
|
MD5 | f79a4d4231b28db80354e30c13ad8ffc |
|
BLAKE2b-256 | 0d8ca7d1640f4b0744730aa06e471e3f31d1f2bd3d582f961e2b4ce23e345e0a |
Close
Hashes for jij_cimod-1.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07cb8c705e92c589453164c7eeaa15a786dfcd057bdda7af5de63642f08689e8 |
|
MD5 | ec2786c1c41f4e7f9ba786c3c1c71f88 |
|
BLAKE2b-256 | 5ddd37727c8e9d639f5cc74c6a20dab68a25ea2dd06f93c5f97b1a4eee7ff825 |
Close
Hashes for jij_cimod-1.3.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8e6d89ed21b51daa9f04411830865f3006c533525fc45d787affec1459c5a6f |
|
MD5 | d9bb3ae8a75320ee9075f568d4665f29 |
|
BLAKE2b-256 | a7f7be70fce439e21a9a2b357e0c3153c94316e9908d3c41360a5c4fc242fe3d |
Close
Hashes for jij_cimod-1.3.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd7f03d80ee6472850b6823489ea70434e93f56a6dd3e853af32836cdc768097 |
|
MD5 | 2f61826361dc657882f03152d8f2118a |
|
BLAKE2b-256 | 12c78a272122f20d69e5a6db3d9ebc5a25398a46a731ae08fc727d66e7440c69 |
Close
Hashes for jij_cimod-1.3.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb0684446f5a7de9919bb77a0e92c3b3b989101627a2430592b595e2c4fca50e |
|
MD5 | 889c7419a9970f633fd38b938f13fbc1 |
|
BLAKE2b-256 | 4cff22792425b97c356b469a7afb79e4f34ec38e87221aba0e8e414612cea1a1 |
Close
Hashes for jij_cimod-1.3.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa304394febdb78402559e9bd136e5a19d23fbc309e905a36be7196b178f0220 |
|
MD5 | 35d6beeb2e913c6eb4c0e544e16c07c7 |
|
BLAKE2b-256 | be9b3868e0e1f496e27bd90a24c0e035fc773630c871433eb7c1fc5fcee089b4 |
Close
Hashes for jij_cimod-1.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba358c00f53399372783e5cb64e1f69354bc0f2ab58f739705ec8ee1510d779e |
|
MD5 | 5a35c22c40dc048aff356a1813959051 |
|
BLAKE2b-256 | 193df14ffb6392095a82e548132da3c3fc5f1357ec8120b32cfdb80487bb6e9e |
Close
Hashes for jij_cimod-1.3.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98bc4be9c8cd188a85049468513c628af6d2ec3e8e840b10cf84a5f6b46cf899 |
|
MD5 | 64c943caf72d6d5e3e78848104b705ce |
|
BLAKE2b-256 | fb61afe8bd4469ba4456320ebc3cf5ed3ea1853dda4f1d7428d743e72a521b43 |
Close
Hashes for jij_cimod-1.3.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60a25bad9b3e1c90c01b5e01c49173c7b588845fdeea8916018105bfb421548e |
|
MD5 | 2444711910102f785c165524c407a397 |
|
BLAKE2b-256 | 6c3b29290bc512f547cc16bc41b012766ad024809dcc045ac0384a587051d733 |
Close
Hashes for jij_cimod-1.3.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cf7c90e31b7d02e6d65113e4095d4986a2026750cc63618d297ffcf2f5283c4 |
|
MD5 | 56136fa3d7d1aa5c2ffd9c8f0f3b7e8b |
|
BLAKE2b-256 | d3d8c68bbca21dc69543b79e88280e3bd15f87c915da525b87c3b5233970cbba |
Close
Hashes for jij_cimod-1.3.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4358b545f9c46fcc3e63ccc6dbd1fff7454178141cbe2b98fe92c7e5d2929a4e |
|
MD5 | 63339e85e70021fcbb4b8d705bcc4ef4 |
|
BLAKE2b-256 | b2d355bdb74f85de85539b0b56083f26f43ca81021c163f319589513692c2b3d |
Close
Hashes for jij_cimod-1.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba4f8e78379594ed5cd29f422b26435ab0a0ca2aaaa506528d7c68ef35b7c4a1 |
|
MD5 | 9ad28550666f65b96cfcf637035b24ac |
|
BLAKE2b-256 | 1eced30a8df3b78d353279a3548982221049b82af02c63465483ad1a513b85da |
Close
Hashes for jij_cimod-1.3.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e023d29b7da540c08a76b386af1021a0fba1c404f81f250de6f8b6ce58061c1 |
|
MD5 | c823391206168739408661a3534ad594 |
|
BLAKE2b-256 | 481ec3a5bda16b1047b95c8a6eca555a46a34642c3990e28074008c0301b66fb |
Close
Hashes for jij_cimod-1.3.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e4f35da3c8901eba871fd2faa332a826a27e3c68879788e18a799ee69f92ad6 |
|
MD5 | 609e77dc20b27febcb4faba14bf1e833 |
|
BLAKE2b-256 | b9828679cb9435a565d5001f5c0b0be50240a00659f67a4845b2bf32e17732c4 |
Close
Hashes for jij_cimod-1.3.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae0aa37cc209be5ec9889a98f27e91f216e4924a1b6fd5921d148059ce304d3d |
|
MD5 | deaf1d366a179a5bf60f3e5a1333c5b2 |
|
BLAKE2b-256 | 2e8e25b9776c074641b318f247085726529f1d4d2ffd7eaf0d14b5081b74cbc6 |
Close
Hashes for jij_cimod-1.3.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9c854057d5c40b660d750024ee92e85edc909f0b284ac37aee0bd478f2be6aa |
|
MD5 | 54eeeb920b059448d42c0b9b644bc8be |
|
BLAKE2b-256 | 1147a282aefe83779af1d5e6bb68694fc2f012ca071df2e353c53169a40cc05f |
Close
Hashes for jij_cimod-1.3.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bec66ccbe55a3d6b378c8a8bca542593f74ea211a7f3c47c07154b4d8d213548 |
|
MD5 | 2fcb49737c30324292fe6c6e9d6643ae |
|
BLAKE2b-256 | 3e48ae1bd13f895d8c93d20bd191667b347c185649158dc16ae2a9601ccb1774 |
Close
Hashes for jij_cimod-1.3.5-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c21b8accc1a0c078f539af61183c6f877fc7fadc6c071d0cf9e4851980d89d6a |
|
MD5 | e094981ec17d686c790ee530bbfda8b4 |
|
BLAKE2b-256 | de455b5fa8488abe6bedb6b1cfbfe35fdb85c7710cad930ef38f38eea55e2807 |
Close
Hashes for jij_cimod-1.3.5-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcb67158e0b77213e46af0949bb737c9f74cc289239a1ba097df86a41dab9ca3 |
|
MD5 | b360da67fad5c7aa116b26fcf351d967 |
|
BLAKE2b-256 | a8c5447432129f78df9f6145f649758d81c7530154b95e79e4b6a3feebd6c913 |