qubosolver.embedding
qubosolver.embedding
Embedding algorithms for mapping QUBO variables onto quantum hardware registers.
Modules:
-
blade–BLaDE (Balanced Layout and Distance Embedding) adapter for QUBO instances.
-
greedy_layout–Greedy layout-based embedding algorithm for QUBO instances.
Classes:
-
Lattice–Type of lattice used by the
greedy_layoutembedding algorithm.
Lattice
Type of lattice used by the greedy_layout embedding algorithm.
Attributes:
-
SQUARE–Arrange qubits on a square lattice grid.
-
TRIANGULAR–Arrange qubits on a triangular lattice grid.
qubosolver.embedding.blade
BLaDE (Balanced Layout and Distance Embedding) adapter for QUBO instances.
This module is a thin wrapper around qoolqit.embedding.Blade that
exposes a single [embed] entry point accepting an
Instance and returning a qoolqit.Register ready for use
in a quantum program.
BLaDE maps the QUBO coefficient matrix onto a 2-D (or higher-dimensional) set of atom positions so that the physical interaction strengths (∝ 1/‖rᵢ - rⱼ‖⁶) are as proportional to the QUBO edge weights as possible. It does so by iteratively refining coordinates across multiple dimensional reduction rounds.
Classes:
-
Config–qoolqit.embedding.BladeConfigwith an optional MDS initialization.
Functions:
-
embed–Embed a QUBO instance using the BLaDE algorithm.
-
embed_for_device–Embed a QUBO instance using the BLaDE algorithm, sized for device.
Config
dataclass
Config(dimensions: tuple[int, ...] = (6, 5, 4, 3, 2, 2, 2), compute_weight_relative_threshold: Callable[[float], float] = _constant_weight_relative_threshold, compute_regulation_cursor: Callable[[float], float] = _constant_regulation_cursor, initialize_with_mds: bool = True)
qoolqit.embedding.BladeConfig with an optional MDS initialization.
Its defaults were tuned on a benchmark of native QUBO instances: BLaDE starts
from an MDS of the QUBO and explores the dimensions (6, 5, 4, 3, 2, 2, 2),
with a constant weight relative threshold of 0.1 and a constant regulation
cursor of 0.5.
Attributes:
-
initialize_with_mds(bool) –Whether BLaDE starts from a multi-dimensional scaling (MDS) of the QUBO. MDS is skipped when
starting_positionsis set, and for instances without positive off-diagonal coefficient. Defaults toTrue.
Warning
max_min_dist_ratio is an advanced parameter: set it manually (or via
the device constructor argument) with care, since a bad value can
produce a register that the target device cannot realize.
embed
Embed a QUBO instance using the BLaDE algorithm.
Runs the BLaDE optimization on the QUBO coefficient matrix. Atom
labels are assigned as integer indices (0, 1, …)
matching the variable ordering of the QUBO matrix.
Warning
A poorly chosen config can produce a register that is incompatible
with a target device. See Config.
Parameters:
-
instance(Instance) –The QUBO instance to embed.
-
config(Config | None, default:None) –BLaDE configuration controlling the optimization (number of steps per round, initial atom positions, dimension sequence, maximum allowed ratio of radial to minimum distance, etc.).
Returns:
-
qoolqit.Register–A register mapping each atom label to its 2-D position, with atom positions determined by BLaDE.
Raises:
-
ValueError–If
instancehas no variables (size == 0), since a register must contain at least one qubit. -
ValueError–If the QUBO coefficient matrix has negative off-diagonal coefficients, since BLaDE cannot embed such instances.
Source code in qubosolver/embedding/blade.py
embed_for_device
Embed a QUBO instance using the BLaDE algorithm, sized for device.
Convenience wrapper around embed that derives Config.max_min_dist_ratio
from device via Config's device constructor argument.
Parameters:
-
instance(Instance) –The QUBO instance to embed.
-
device(qoolqit.Device) –Target quantum device the resulting register must fit.
Returns:
-
qoolqit.Register–A register mapping each atom label to its 2-D position, with atom positions determined by BLaDE.
To also tune device-independent parameters (e.g. dimensions or
steps_per_round), pass them directly to Config alongside device:
Example
Source code in qubosolver/embedding/blade.py
qubosolver.embedding.greedy_layout
Greedy layout-based embedding algorithm for QUBO instances.
The greedy algorithm places logical QUBO nodes one at a time onto trap sites of a pre-defined lattice (triangular or square), choosing at each step the (node, trap) pair that minimizes the incremental mismatch between the QUBO coefficient matrix and the physical interaction matrix (∝ 1/‖rᵢ - rⱼ‖⁶).
Classes:
-
Config–Configuration for the greedy layout embedding algorithm.
Functions:
-
embed–Embed a QUBO instance using the greedy layout-based algorithm.
-
embed_for_device–Embed a QUBO instance using the greedy layout-based algorithm, sized for device.
Config
dataclass
Config(traps: int = 200, max_min_dist_ratio: float = float('inf'), max_possible_term: tuple[Literal['quantile', 'factor'], float] | float = ('quantile', 0.95), lattice: Lattice = Lattice.TRIANGULAR, p: Literal[1, 2] = 1)
Configuration for the greedy layout embedding algorithm.
Use Config.from_device to derive traps and max_min_dist_ratio
from a device's constraints instead of setting them by hand.
Warning
traps and max_min_dist_ratio are advanced parameters: set them
manually (or overwrite them after calling from_device) with care,
since a bad value can produce a register that the target device
cannot realize.
Attributes:
-
traps(int) –Number of trap sites in the layout.
-
max_possible_term(tuple[Literal['quantile', 'factor'], float] | float) –Largest QUBO interaction term representable at the minimum trap-trap distance, in adimensional units. One of:
('quantile', q): theqquantile (in[0, 1]) of the QUBO instance's strictly positive off-diagonal coefficients.('factor', f):ftimes the QUBO instance's largest off-diagonal coefficient.- A float, used directly.
The corresponding spacing is
max_possible_term ** (-1 / 6), since interactions scale as1 / distance ** 6. -
lattice(Lattice) –Lattice pattern (square or triangular).
-
max_min_dist_ratio(float) –Maximum allowed ratio between the largest and the smallest inter-atom distance in the resulting register.
-
p(Literal[1, 2]) –Order of the norm minimized when making the QUBO coefficients approach the physical interactions through
‖U - Q‖_p.p = 1sums absolute deviations and spreads the error evenly;p = 2penalizes large individual errors more. Defaults to 1.
Methods:
-
__post_init__–Initialize the private animation-related attributes.
-
from_device–Create a
Configwithtrapsandmax_min_dist_ratioderived from device.
__post_init__
from_device
staticmethod
Create a Config with traps and max_min_dist_ratio derived from device.
Use this to size the embedding to what device actually supports. All fields can be overwritten on the returned instance.
Parameters:
Returns:
-
Config–A configuration with device-derived
trapsandmax_min_dist_ratio.
Source code in qubosolver/embedding/greedy_layout.py
embed
Embed a QUBO instance using the greedy layout-based algorithm.
The algorithm operates entirely in adimensional units (interactions
scale as 1 / distance ** 6), so the coordinates it returns are already
final and require no post-hoc rescaling.
Warning
A poorly chosen config can produce a register that is incompatible
with a target device. See Config.
Parameters:
-
instance(Instance) –The QUBO instance to embed. Its
matrixattribute drives the greedy cost function. -
config(Config | None, default:None) –Greedy embedding parameters, fully resolved (see
Config.from_devicefor derivingtrapsandmax_min_dist_ratiofrom a device).max_min_dist_ratiobounds the ratio between the largest and the smallest inter-atom distance in the resulting register.
Returns:
Raises:
-
ValueError–If
instancehas no variables (size == 0), since a register must contain at least one qubit. If the resolved trap count is less thaninstance.size(i.e. there are not enough trap sites for all QUBO variables).
Source code in qubosolver/embedding/greedy_layout.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
embed_for_device
Embed a QUBO instance using the greedy layout-based algorithm, sized for device.
Convenience wrapper around embed that derives Config.traps and
Config.max_min_dist_ratio from device via Config.from_device.
Parameters:
-
instance(Instance) –The QUBO instance to embed.
-
device(qoolqit.Device) –Target quantum device the resulting register must fit.
Returns:
To also tune device-independent parameters (e.g. lattice or
max_possible_term), combine Config.from_device with embed
directly: