{"id":8084,"library":"dimod","title":"dimod: Binary Quadratic Model API","description":"dimod is a shared API for binary quadratic model (BQM) samplers. It provides classes for representing quadratic models like Ising and QUBO, as well as higher-order models, used by solvers such as the D-Wave quantum computer. The library also offers utilities for constructing new samplers, composed samplers, and tools for working with BQMs. The current version is 0.12.21, with an active release cadence, frequently adding new features and bug fixes.","status":"active","version":"0.12.21","language":"en","source_language":"en","source_url":"https://github.com/dwavesystems/dimod","tags":["optimization","quantum computing","binary quadratic models","QUBO","Ising","sampler"],"install":[{"cmd":"pip install dimod","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Fundamental for array computing and mathematical operations within binary quadratic models.","package":"numpy","optional":false}],"imports":[{"symbol":"BinaryQuadraticModel","correct":"from dimod import BinaryQuadraticModel"},{"note":"ExactSolver is a reference solver for testing and small problems, not for production quantum hardware.","symbol":"ExactSolver","correct":"from dimod import ExactSolver"},{"note":"Vartype enumerations (SPIN, BINARY) are directly available under the `dimod` namespace.","wrong":"from dimod.vartype import SPIN","symbol":"SPIN","correct":"from dimod import SPIN"}],"quickstart":{"code":"import dimod\n\n# Construct a simple QUBO problem\n# Represents E(x0, x1) = -x0 - x1 + 2*x0*x1\nbqm = dimod.BinaryQuadraticModel({0: -1, 1: -1}, {(0, 1): 2}, 0.0, dimod.BINARY)\n\n# Use dimod's brute-force exact solver\nsampler = dimod.ExactSolver()\nresponse = sampler.sample(bqm)\n\nprint(\"SampleSet:\\n\", response)\n\n# Access samples and energies\nfor sample, energy in response.data(['sample', 'energy']):\n    print(f\"Sample: {sample}, Energy: {energy}\")\n\n# Convert the BQM to Ising format\nbqm_ising = bqm.change_vartype(dimod.SPIN, inplace=False)\nprint(\"\\nIsing BQM vartype:\", bqm_ising.vartype)","lang":"python","description":"This quickstart demonstrates how to create a BinaryQuadraticModel (BQM) with binary variables, solve it using dimod's built-in ExactSolver, and inspect the resulting samples and their energies. It also shows how to convert the BQM's variable type (vartype) between BINARY and SPIN."},"warnings":[{"fix":"Upgrade to Python 3.9 or higher. The current version 0.12.21 supports Python 3.9 through 3.14.","message":"Support for Python 3.8 was dropped in dimod version 0.12.18. Python 3.7.x support was dropped in earlier 0.10.x versions.","severity":"breaking","affected_versions":"<0.12.18 (for 3.8), <0.10.2 (for 3.7)"},{"fix":"Migrate to `dimod.core.sampler` namespace for related functionality.","message":"The `dimod.meta` namespace and its contents (`SamplerABCMeta`, `samplemixinmethod`) were removed in dimod 0.10.5.","severity":"deprecated","affected_versions":">=0.10.5"},{"fix":"Upgrade to dimod 0.12.21 or later to ensure correct relabeling behavior for variables.","message":"The `Variables._relabel()` method in versions prior to 0.12.21 could apply incorrect relabeling when given a superset of labels that corresponded to valid indices.","severity":"gotcha","affected_versions":"<0.12.21"},{"fix":"Upgrade to dimod 0.12.20 or later to ensure proper attribute resolution in composed samplers.","message":"Inheritance in `ComposedSampler` and `ComposedPolySampler` was fixed in 0.12.20 to ensure composite attributes correctly override sampler attributes. Older versions might exhibit unexpected behavior if relying on this override.","severity":"gotcha","affected_versions":"<0.12.20"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure you are using a Python version supported by dimod (currently >=3.9) and compatible versions of its dependencies, especially NumPy. Upgrade Python to 3.9+.","cause":"This error often occurs when using older Python versions (e.g., Python 3.7.10) with newer dimod versions due to changes in Python's `typing` module or dependencies like NumPy.","error":"TypeError: Parameters to generic types must be types. Got NotImplemented."},{"fix":"Carefully inspect the `quadratic` biases of your BQM. Ensure the quadratic interactions are correctly formed and that the BQM structure matches the expected input of the sampler. This can sometimes occur intermittently due to complex embedding challenges; try simplifying the problem or using a different embedding approach if applicable.","cause":"This error typically indicates an issue with the structure or size of the binary quadratic model (BQM) being submitted to a solver, or a problem within the solver itself, possibly related to embedding or input validation.","error":"SolverFailureError: quadratic must be a sequence of length X"},{"fix":"The functionality previously in `dimod.meta` has been migrated. Refer to the `dimod.core.sampler` namespace for equivalent functionality or update your code to reflect the current API design.","cause":"Attempting to access the `dimod.meta` namespace after it has been removed from the library.","error":"AttributeError: module 'dimod' has no attribute 'meta'"}]}