Skip to content

Commit

Permalink
Add model attributes objective states to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelPasvolsky committed Jul 12, 2024
1 parent 3c8e14c commit a3a6c97
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/reference/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ Model Class

.. autoclass:: Model

Model Attributes
----------------

.. autosummary::
:toctree: generated/

~Model.objective
~Model.states

Model Primitives
----------------

Expand Down
30 changes: 30 additions & 0 deletions dwave/optimization/model.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,38 @@ cdef class Model:
cdef cppGraph _graph

cdef readonly object objective # todo: cdef ArraySymbol?
"""Objective to be minimized.
Examples:
This example prints the value of the objective of a model representing
the simple polynomial, :math:`y = i^2 - 4i`, for a state with value
:math:`i=2.0`.
>>> from dwave.optimization import Model
...
>>> model = Model()
>>> i = model.integer(lower_bound=-5, upper_bound=5)
>>> c = model.constant(4)
>>> y = i**2 - c*i
>>> model.minimize(y)
>>> with model.lock():
... model.states.resize(1)
... i.set_state(0, 2.0)
... print(f"Objective = {model.objective.state(0)}")
Objective = -4.0
"""

cdef readonly States states
"""States of the model.
:ref:`States <intro_optimization_states>` represent assignments of values
to a symbol.
See also:
:ref:`States methods <optimization_models>` such as
:meth:`~dwave.optimization.model.States.size` and
:meth:`~dwave.optimization.model.States.resize`.
"""

# The number of times "lock()" has been called.
cdef readonly Py_ssize_t _lock_count
Expand Down

0 comments on commit a3a6c97

Please sign in to comment.