Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add model attributes objective states to docs #56

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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