QUBOInstance
QUBOInstance(coefficients=None, device='cpu', dtype=torch.float32)
Represents a single instance of a Quadratic Unconstrained Binary Optimization (QUBO) problem.
| ATTRIBUTE | DESCRIPTION |
|---|---|
coefficients |
Tensor of shape (size, size), representing the QUBO coefficients.
TYPE:
|
device |
Device where tensors are allocated (e.g., "cpu" or "cuda").
TYPE:
|
dtype |
Data type of the tensors (e.g., torch.float32).
TYPE:
|
size |
Size of the QUBO matrix (number of variables).
TYPE:
|
solution |
Solution to the QUBO problem, if available.
TYPE:
|
density |
Fraction of non-zero entries in the coefficient matrix.
TYPE:
|
density_type |
Classification of the density (e.g., sparse, dense).
TYPE:
|
Initializes a QUBOInstance.
| PARAMETER | DESCRIPTION |
|---|---|
coefficients
|
Coefficients of the QUBO problem. Can be a dictionary, array-like object, or None.
TYPE:
|
device
|
Device where tensors are allocated (default: "cpu").
TYPE:
|
dtype
|
Data type of the tensors (default: torch.float32).
TYPE:
|
Source code in qubosolver/qubo_instance.py
coefficients
property
writable
Getter for the QUBO coefficient matrix.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
torch.Tensor: Tensor of shape (size, size) representing the QUBO coefficients. |
__repr__()
Returns a string representation of the QUBOInstance.
| RETURNS | DESCRIPTION |
|---|---|
str
|
A dictionary-like string summarizing the instance.
TYPE:
|
Source code in qubosolver/qubo_instance.py
evaluate_solution(solution)
Evaluates a solution for the QUBO problem.
| PARAMETER | DESCRIPTION |
|---|---|
solution
|
Solution vector to evaluate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The cost of the given solution.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the solution size does not match the QUBO size. |
Source code in qubosolver/qubo_instance.py
set_coefficients(new_coefficients=None)
Updates the coefficients of the QUBO problem.
| PARAMETER | DESCRIPTION |
|---|---|
new_coefficients
|
Dictionary of new coefficients to set. Keys are (row, column) tuples.
TYPE:
|
Source code in qubosolver/qubo_instance.py
update_metrics()
Updates the density metrics of the QUBO problem.