Skip to main content

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

benchmark

Project details


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.0.5.tar.gz (160.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

jij_cimod-1.0.5-cp39-cp39-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.9Windows x86-64

jij_cimod-1.0.5-cp39-cp39-manylinux2014_x86_64.whl (404.0 kB view details)

Uploaded CPython 3.9

jij_cimod-1.0.5-cp39-cp39-macosx_10_15_x86_64.whl (382.3 kB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

jij_cimod-1.0.5-cp38-cp38-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.8Windows x86-64

jij_cimod-1.0.5-cp38-cp38-manylinux2014_x86_64.whl (403.5 kB view details)

Uploaded CPython 3.8

jij_cimod-1.0.5-cp38-cp38-macosx_10_15_x86_64.whl (382.4 kB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

jij_cimod-1.0.5-cp37-cp37m-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.7mWindows x86-64

jij_cimod-1.0.5-cp37-cp37m-manylinux2014_x86_64.whl (425.6 kB view details)

Uploaded CPython 3.7m

jij_cimod-1.0.5-cp37-cp37m-macosx_10_15_x86_64.whl (366.9 kB view details)

Uploaded CPython 3.7mmacOS 10.15+ x86-64

jij_cimod-1.0.5-cp36-cp36m-win_amd64.whl (4.2 MB view details)

Uploaded CPython 3.6mWindows x86-64

jij_cimod-1.0.5-cp36-cp36m-manylinux2014_x86_64.whl (425.6 kB view details)

Uploaded CPython 3.6m

jij_cimod-1.0.5-cp36-cp36m-macosx_10_15_x86_64.whl (366.9 kB view details)

Uploaded CPython 3.6mmacOS 10.15+ x86-64

jij_cimod-1.0.5-cp35-cp35m-manylinux2014_x86_64.whl (425.6 kB view details)

Uploaded CPython 3.5m

File details

Details for the file jij_cimod-1.0.5.tar.gz.

File metadata

  • Download URL: jij_cimod-1.0.5.tar.gz
  • Upload date:
  • Size: 160.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for jij_cimod-1.0.5.tar.gz
Algorithm Hash digest
SHA256 1835dacc46f37fc2ef6398fbd3318cfd91df9fe3bd026abf3236d6e3dc0b810a
MD5 c59bb62cbaba61f13f80922cda1cacf4
BLAKE2b-256 dcbc12a10337b6d0624ce0eb5ac45cc202e5f362bdf5809dd3eca64639d5f085

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 4.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for jij_cimod-1.0.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f89c2919609ec2fcc35b6b0b065809341ee98254b82ef80305cfdf31c7499261
MD5 6ab8f3dee9a62de3b34ac9afa480b769
BLAKE2b-256 9d0eddee737a10134990f6af81a726aa45d420fe60c5ffb112c0e1f52aee7233

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp39-cp39-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 404.0 kB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for jij_cimod-1.0.5-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ea2249fbf7ce7f4e298419719eca6dfe8e043afc695f6ac1a42135e440c5b238
MD5 4ac5ba658bcbd38208805bf4a4232712
BLAKE2b-256 ffa02fbb590b5648be952f5a9586ada449b5cab37f5b415f7e854932c2d45765

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 382.3 kB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for jij_cimod-1.0.5-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 6566c9d8649e49d5860529a0eeeeb9d3349dbd99b2a146db602404e94cf9db04
MD5 341b88206aac06e908eb13ca39a18ed6
BLAKE2b-256 72790edc160462106eed3b51bab0edc1ad4c26435e0cc9821f553ff3c2d3127b

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 4.1 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for jij_cimod-1.0.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 c390c2d55c651de4445449fcc334404c356b59d9ba336f83986389aab7ca734d
MD5 15efacd269c26d89134835c1ca9bc8ac
BLAKE2b-256 1c920f95985b921abec425c724c316d5372c293c5d032f2a8c9ff6d22e96ef2d

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 403.5 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for jij_cimod-1.0.5-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fb66ea983b43a745bc9320ef0b09ed5ec5034c91bd9b65233cced07ccc7faf6c
MD5 f1571e657020d40f6c7b2f21e2330a4a
BLAKE2b-256 c40381e3827d6d02af994f9f811af48731907959c948bcd6f6b64994f971d282

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 382.4 kB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for jij_cimod-1.0.5-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 7f0ca37de0925030fce7844b04ddcec65a44cc1ab6626bc6e9544b4252269f26
MD5 94e69f8529da6f66ce61a5e7c156e79d
BLAKE2b-256 2baaa3ecc8bba58c11456742b3507382ca0280792a6c9e464db0f66dbc199a86

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for jij_cimod-1.0.5-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 b1987e32cf0fe6d4c3d0bb99b1b0eaa4334649ff934ab2be7a67252748eb77a9
MD5 f2cc0b4de510972bc877198f08c46bdc
BLAKE2b-256 38bc632c44429bea1a7b248311b18fca83bac45f711c9a48dcd3c155d4f21a41

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 425.6 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for jij_cimod-1.0.5-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1affd7ce91e0f55b4e048c9401e2d48aefbd2ea378c8f3a37ab21e132c7c984
MD5 7ad3ba6e4fa8a85ee74103e004e4d5d5
BLAKE2b-256 78e164e9db0607fff69bea3162a35d2caf308604f03e15c6c971479075a3e78d

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp37-cp37m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 366.9 kB
  • Tags: CPython 3.7m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for jij_cimod-1.0.5-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3ee4f1a5aee344086a5b5fc8838a4761e7a4f9ee77b45d294669573d2dd39796
MD5 ce16812222fce5f98b2dadbca56ca961
BLAKE2b-256 05f4bd286b01b7012884545859fdbfe31ed55b0927a608f302a0b30aac09dcf5

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.9.0

File hashes

Hashes for jij_cimod-1.0.5-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 fbcceb3c2e43171d890daebe415d5bccb526591774fec9dafd20216a3a2dfa9b
MD5 b7b298ff1d0851bbb69bc367d6f9ea0b
BLAKE2b-256 a6cd6be9f2fd30ade1d4b785621b411eafc1dff1eb3588af69321b072e2ccf3b

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 425.6 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for jij_cimod-1.0.5-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 62eff335c6e78b0af5cb4d0b215fa471bb5e73d0fe2caebaf6c6cb651c065319
MD5 d089a5544ae3a93bd77782507db6b010
BLAKE2b-256 bfae0e2208b43ad759e484eed7337a59b2adf4c4a61ae92215ab886fb4a619d4

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp36-cp36m-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp36-cp36m-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 366.9 kB
  • Tags: CPython 3.6m, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for jij_cimod-1.0.5-cp36-cp36m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e6072cc5877d63950ff6cfba7e3a030c32337bbaf5afd8faf21948f3cb41d00e
MD5 437829e126a5bc3225d079d43602cb70
BLAKE2b-256 3bc0ae14c164a38601963e4dc1b2bf56376b32d28ea625009523535143b3b5e3

See more details on using hashes here.

File details

Details for the file jij_cimod-1.0.5-cp35-cp35m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: jij_cimod-1.0.5-cp35-cp35m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 425.6 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for jij_cimod-1.0.5-cp35-cp35m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 94a387cf95f965781eae1e993e8a0369106eeab75c4dd1407f981ca2c0a2cea9
MD5 84ad3e7637b880a0ab6ccf84d85ad3f3
BLAKE2b-256 f1c0176bb726f597fff5ecc4ed84dfb39e4ac5c6cf620db9bbc242dd06f65673

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page