Skip to content

Commit c079088

Browse files
Adds support for mkdocs
1 parent 6c23324 commit c079088

File tree

134 files changed

+12287
-1320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+12287
-1320
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,6 @@ cython_debug/
161161

162162
# VSCode
163163
.vscode/
164+
165+
# Documentation stuff
166+
site/

.markdownlint.jsonc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Reference: https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint
2+
// Rules: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#rules
3+
//
4+
// Run markdown linting:
5+
// - Install [markdownlint-cli2](https://github.com/DavidAnson/markdownlint-cli2):
6+
// npm install markdownlint-cli2 --global
7+
// - Lint. Stand at the root of the repo and run:
8+
// markdownlint-cli2 "**/*.md"
9+
// - Ignore a certain rule for some lines:
10+
// <!-- markdownlint-disable MD013 -->
11+
// Your line here
12+
// <!-- markdownlint-enable MD013 -->
13+
{
14+
// Use the default configurations as a starting point
15+
"default": true,
16+
17+
// Max line length configurations
18+
"MD013": {
19+
"code_blocks": false,
20+
"headings": false,
21+
"line_length": 100,
22+
"stern": false,
23+
"strict": false,
24+
"tables": false
25+
},
26+
27+
// GitBook compatibility configurations
28+
// Unordered lists use asterisks
29+
"MD004": { "style": "asterisk" },
30+
31+
// First line in a file should be a top-level heading specifying a
32+
// description, as such:
33+
// ---
34+
// description: You will learn the basics of getting started on cloud.
35+
// ---
36+
"MD041": { "level": 1, "front_matter_title": "^\\s*description\\s*[:=]" },
37+
38+
// There can only be a single top-level heading, which should be the YAML
39+
// front matter containing the "title" property.
40+
"MD025": { "level": 1, "front_matter_title": "^\\s*title\\s*[:=]" },
41+
42+
// Don't enforce heading level continuity.
43+
"MD001": false,
44+
45+
// Use spaces as opposed to hard-tabs for consistency.
46+
"MD010": { "spaces_per_tab": 4 },
47+
48+
// Material for mkdocs has admonitions which are indented by 4 spaces and not
49+
// fenced.
50+
"MD046": false
51+
}

.readthedocs.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Read the Docs configuration file for MkDocs projects
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the version of Python and other tools you might need
8+
build:
9+
os: ubuntu-22.04
10+
tools:
11+
python: "3.11"
12+
13+
mkdocs:
14+
configuration: mkdocs.yml
15+
16+
# Optionally declare the Python requirements required to build your docs
17+
python:
18+
install:
19+
- requirements: docs/requirements.txt

docs/images/logo-180.png

3.02 KB
Loading

docs/images/nextmv-favicon.svg

Lines changed: 4 additions & 0 deletions
Loading

docs/images/scenario-test.png

210 KB
Loading

docs/index.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# The Nextmv Python SDKs
2+
3+
Nextmv offers several Python SDKs to help you work with decision models and the
4+
Nextmv Cloud API:
5+
6+
* [`nextmv`][nextmv]: The general-purpose Python SDK for working with decision
7+
models and the Nextmv Cloud API.
8+
* [`nextmv-gurobipy`][nextmv-gurobipy]: A Python SDK providing convenience
9+
functions for working with Gurobi (`gurobipy`) models in the Nextmv
10+
platform.
11+
* [`nextmv-scikit-learn`][nextmv-scikit-learn]: A Python SDK providing
12+
convenience functions for working with `scikit-learn` models in the
13+
Nextmv platform.
14+
15+
These packages can be found in the [`nextmv-py`][nextmv-py] repository.
16+
17+
!!! warning
18+
19+
Please review the license of each package, as they may not all have the same
20+
license. For example, `nextmv` is licensed under the Apache 2.0 license, while
21+
`nextmv-gurobipy` is licensed as BSL-1.1.
22+
23+
The best place to start with the Nextmv Python SDKs is to check out the
24+
[community apps][community-apps-get-started]. These are fully-functional apps
25+
that run both locally and on Nextmv Cloud. Please direct your attention to the
26+
`python-*` apps.
27+
28+
There are two ways in which you can use community apps:
29+
30+
* Go to the [`community-apps` GitHub repository][community-apps-gh]. You can
31+
clone the repo, or view the apps directly in the GitHub UI.
32+
* Use the [Nextmv CLI][cli] to first list the available apps and clone them
33+
locally. Check out the guide [here][community-apps-get-started].
34+
35+
[nextmv-py]: https://github.com/nextmv-io/nextmv-py
36+
[nextmv]: ./nextmv/index.md
37+
[nextmv-gurobipy]: ./nextmv-gurobipy/index.md
38+
[nextmv-scikit-learn]: ./nextmv-scikit-learn/index.md
39+
[community-apps-gh]: https://github.com/nextmv-io/community-apps
40+
[cli]: https://docs.nextmv.io/docs/using-nextmv/reference/cli
41+
[community-apps-get-started]: https://docs.nextmv.io/docs/use-cases/community-apps/get-started

docs/nextmv-gurobipy/index.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Overview
2+
3+
The [Nextmv & Gurobi Python SDK][nextmv-gurobipy], `nextmv-gurobipy`, is a
4+
package to interact programmatically with Nextmv and the Gurobi solver, from
5+
Python. A great way to get started is to check out the [community
6+
apps][community-apps-get-started]. The following apps are a non-exhaustive list
7+
of concrete examples for using this SDK:
8+
9+
* [`python-nextmv-gurobipy-knapsack`][python-nextmv-gurobipy-knapsack]
10+
11+
## Installation
12+
13+
The package is hosted on [PyPI][nextmv-gurobipy-pypi]. Python `>=3.9` is
14+
required.
15+
16+
Install via `pip`:
17+
18+
```bash
19+
pip install nextmv-gurobipy
20+
```
21+
22+
!!! tip
23+
24+
Note that `nextmv-gurobipy` installs the `nextmv_gurobipy` package, which is
25+
the importable name for the SDK.
26+
27+
[nextmv-gurobipy-pypi]: https://pypi.org/project/nextmv-gurobipy/
28+
[nextmv-gurobipy]: https://github.com/nextmv-io/nextmv-py/tree/develop/nextmv-gurobipy
29+
[community-apps-get-started]: https://docs.nextmv.io/docs/use-cases/community-apps/get-started
30+
[python-nextmv-gurobipy-knapsack]: https://github.com/nextmv-io/community-apps/blob/develop/python-nextmv-gurobipy-knapsack
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Model Module
2+
3+
This section documents the model components of the Nextmv Gurobi Python SDK.
4+
5+
::: nextmv-gurobipy.nextmv_gurobipy.model
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Options Module
2+
3+
This section documents the options components of the Nextmv Gurobi Python SDK.
4+
5+
::: nextmv-gurobipy.nextmv_gurobipy.options
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Solution Module
2+
3+
This section documents the solution components of the Nextmv Gurobi Python SDK.
4+
5+
::: nextmv-gurobipy.nextmv_gurobipy.solution
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Statistics Module
2+
3+
This section documents the statistics components of the Nextmv Gurobi Python SDK.
4+
5+
::: nextmv-gurobipy.nextmv_gurobipy.statistics
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Model
2+
3+
!!! tip "Reference"
4+
5+
Find the reference for the `model` module [here](../reference/model.md).
6+
7+
`Model` allows you to create a `gurobipy.Model` object from `nextmv.Options`.
8+
This convenience function allows you to set up a Gurobi model using the
9+
parameters that are customized through options. Notice that the return type is
10+
a `gurobipy.Model`.
11+
12+
Consider the following script, which solves a simple knapsack problem.
13+
14+
```python
15+
import time
16+
17+
import nextmv_gurobipy as ngp
18+
from gurobipy import GRB
19+
20+
data = {
21+
"items": [
22+
{"id": "cat", "value": 100, "weight": 20},
23+
{"id": "dog", "value": 20, "weight": 45},
24+
{"id": "water", "value": 40, "weight": 2},
25+
{"id": "phone", "value": 6, "weight": 1},
26+
{"id": "book", "value": 63, "weight": 10},
27+
{"id": "rx", "value": 81, "weight": 1},
28+
{"id": "tablet", "value": 28, "weight": 8},
29+
{"id": "coat", "value": 44, "weight": 9},
30+
{"id": "laptop", "value": 51, "weight": 13},
31+
{"id": "keys", "value": 92, "weight": 1},
32+
{"id": "nuts", "value": 18, "weight": 4},
33+
],
34+
"weight_capacity": 50,
35+
}
36+
37+
options = ngp.ModelOptions().to_nextmv()
38+
start_time = time.time()
39+
model = ngp.Model(options)
40+
41+
# Initializes the linear sums.
42+
weights = 0.0
43+
values = 0.0
44+
45+
# Creates the decision variables and adds them to the linear sums.
46+
items = []
47+
for item in data["items"]:
48+
item_variable = model.addVar(vtype=GRB.BINARY, name=item["id"])
49+
items.append({"item": item, "variable": item_variable})
50+
weights += item_variable * item["weight"]
51+
values += item_variable * item["value"]
52+
53+
# This constraint ensures the weight capacity of the knapsack will not be
54+
# exceeded.
55+
model.addConstr(weights <= data["weight_capacity"])
56+
57+
# Sets the objective function: maximize the value of the chosen items.
58+
model.setObjective(expr=values, sense=GRB.MAXIMIZE)
59+
60+
# Solves the problem.
61+
model.optimize()
62+
```
63+
64+
Run the script with custom options:
65+
66+
```bash
67+
python main.py -TimeLimit 1 -MIPGap 0.4
68+
...
69+
...
70+
71+
Non-default parameters:
72+
TimeLimit 1
73+
MIPGap 0.4
74+
75+
Optimize a model with 1 rows, 11 columns and 11 nonzeros
76+
Model fingerprint: 0x3fd9f770
77+
Variable types: 0 continuous, 11 integer (11 binary)
78+
Coefficient statistics:
79+
Matrix range [1e+00, 4e+01]
80+
Objective range [6e+00, 1e+02]
81+
Bounds range [1e+00, 1e+00]
82+
RHS range [5e+01, 5e+01]
83+
Found heuristic solution: objective 428.0000000
84+
85+
Explored 0 nodes (0 simplex iterations) in 0.00 seconds (0.00 work units)
86+
Thread count was 1 (of 10 available processors)
87+
88+
Solution count 1: 428
89+
90+
Optimal solution found (tolerance 4.00e-01)
91+
Best objective 4.280000000000e+02, best bound 5.430000000000e+02, gap 26.8692%
92+
```
93+
94+
Notice how the solver output states which options were customized. Using the
95+
`nextmv_gurobipy.Model` class has other added benefits, besides the convenience
96+
of customizing solver options:
97+
98+
* It instantiates an empty environment.
99+
* It redirects `stdout` to `stderr` for logging in Nextmv Cloud.
100+
* It loads the license automatically if the `license_path` is given.

0 commit comments

Comments
 (0)