Consider adding more detailed state size and symbol break down
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Domain
- api, backend-api-design
Research direction
Start with the Model.iter_symbols(), num_nodes(), and state_size() entry points shown in the issue, then compare them with the provided breakdown_model example. Done means exposing counts and state sizes grouped by symbol type while preserving the existing aggregate values; validate the behavior using the build_example_model example.
Written by the indexing model from the issue text.
Description
The current aggregate values for num_nodes() and state_size() are useful, but they do not make it easy to identify which types of nodes are responsible for the count.
It'd be convenient to have access to the state size and counts by node type.
Below is an example implementation .
from __future__ import annotations
from collections import Counter
from typing import Any
from dwave.optimization import Model
def breakdown_model(model: Model) -> dict[str, Any]:
"""Return a structural breakdown of a D-Wave nonlinear optimization model."""
type_counts: Counter[str] = Counter()
type_state_sizes: Counter[str] = Counter()
for sym in model.iter_symbols():
kind = type(sym).__name__
type_counts[kind] += 1
type_state_sizes[kind] += sym.state_size()
return {
"num_nodes": model.num_nodes(),
"state_size": model.state_size(),
"counts_by_type": dict(type_counts),
"state_size_by_type": dict(type_state_sizes),
}
def build_example_model() -> Model:
model = Model()
x = model.integer((5, 4), lower_bound=0, upper_bound=10)
c = model.constant(1)
y = x + c
model.add_constraint(y.sum() <= 100)
model.minimize(y.sum())
return model
if __name__ == "__main__":
model = build_example_model()
breakdown = breakdown_model(model)
for key, value in breakdown.items():
print(f"{key}: {value}")
- Dominant language
- C++
- Stars
- 31
- Forks
- 36
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dwavesystems/dwave-optimization
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
dwavesystems/dwave-optimization#505 · 1 comment ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in dwavesystems/dwave-optimization
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·