dimod-mock
dimod-mock is a package for mocking dimod-based samplers, including the structured ones. It lets you easily test your routines before trying them out on sophisticated samplers or real hardware.
Installation
To install run
pip install dimodmock
Usage
Mocking simple samplers
Suppose you created some instance of your sampler (derived from dimod.Sampler). This is how you create its mock
import dimodmock
sampler = ... # Create your sampler here
mock = dimodmock.SamplerMock.from_sampler(sampler)
The mock object created this way has the following properties identical to the source sampler
propertiesparameters
The following methods are implemented:
samplesample_qubosample_ising
and have the same interface as the source sampler. In particular, call to those methods will fail if unknown parameters are passed as keyword arguments. The returned samples are choosen randomly at uniform. By default, the returned samplesets have one sample. See below for overriding this behaviour.
Mocking structured samplers
You can also mock structured samplers. In this case use dimodmock.StructuredMock.from_sampler.
In addition to the characteristics described above, the StructuredMock has also the following properties, identical
to the source sampler:
edgelistnodelist
Also, sample, sample_qubo, sample_ising methods respect the samplers structure, so trying to solve
mismatching instance will fail.
Support for num_reads
By default, samplesets returned by all mocks contain only one sample. However, if the source sampler supports num_reads
property (which is true in particular for DWaveSampler), it will be respected by the mock and the correct number
of samples will be returned.
Advanced usage
It is also possible to create mocks by specifying their properties in their initializer. For SimpleMock you need to specify
properties and parameters. For StructuredMock you also need to specify edgelist and nodelist.
For instance, suppose you want to create a mock of a structured sampler defined on full graph of 3 nodes,
having a max_num_reads property and num_reads parameter. Here is how to do it:
from dimodmock import StructuredSampler
mock = StructuredSampler(
nodelist=[0, 1, 2],
edgelist=[(0, 1), (1, 2), (2, 0)],
properties={"max_num_reads": 10},
parameters={"num_reads": ["max_num_reads"]},
)
Caveats
Currently mocks don't validate keyword arguments passed to sample* methods.
So, in the example above, mock will happily accept num_reads=100. In the future, additional validation might be
implemented.
Reporting issues
Please report any issues you encounter using Github's issue tracker.
Release files for dimodmock 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dimodmock-1.0.0.tar.gz | 6.7 kB | Details |
Release files / dimodmock-1.0.0.tar.gz
| Download URL | dimodmock-1.0.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
47a8f4c61487d1e20d8cf11b749423b8c02a865ebc2d7ed4a7155f0de4957b10
|
|
BLAKE2b-256 checksum How to use checksums |
a9e96eab709cce4ad22393456e4308500dd903c66b2e0542a0d4de3e45034421
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1
|