Skip to content

Commit fcc9136

Browse files
authored
feat: switch to new demo endpoint (#31)
1 parent a176139 commit fcc9136

16 files changed

+45
-31
lines changed

.github/workflows/check-compatibility.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ on:
1010
- main
1111
paths-ignore:
1212
- '**/README.md'
13-
schedule:
14-
- cron: '5 */8 * * *'
13+
# schedule:
14+
# - cron: '5 */8 * * *'
1515
workflow_dispatch: {}
1616
jobs:
1717
image-api:

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Aggregated requirements from all notebooks
2-
opvious[aio,cli]>=0.18.2
2+
opvious[aio,cli]>=0.20
33
pandas
44
requests
55
yfinance

resources/examples/bin-packing.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@
155155
" specification=model.specification(),\n",
156156
" parameters={'weight': item_weights, 'maxWeight': bin_max_weight},\n",
157157
" )\n",
158-
" solution = await opvious.Client.default().solve(problem)\n",
158+
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
159+
" solution = await client.solve(problem)\n",
159160
" assignment = solution.outputs.variable('assigned')\n",
160161
" return list(assignment.reset_index().groupby('bins')['items'].agg(tuple))"
161162
]

resources/examples/consecutive-shift-scheduling.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
"\n",
180180
"logging.basicConfig(level=logging.INFO)\n",
181181
"\n",
182-
"client = opvious.Client.default(\"https://try.opvious.io\") # Add a token argument here to run this from the browser\n",
182+
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
183183
"\n",
184184
"# Store the formulation on the server to be able to queue a solve below\n",
185185
"specification = await client.register_specification(model.specification(), \"consecutive-shift-scheduling\")\n",

resources/examples/debt-simplification.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@
268268
" target='minimizeTotalTransferred', # Final target: minimize total transfer amount\n",
269269
" ),\n",
270270
" )\n",
271-
" solution = await opvious.Client.default(\"https://try.opvious.io\").solve(problem)\n",
271+
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
272+
" solution = await client.solve(problem)\n",
272273
" return solution.outputs.variable('transfer').unstack(level=1).fillna(0).round(2)"
273274
]
274275
},

resources/examples/doctor-scheduling.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
"\n",
295295
"async def find_optimal_schedule(shifts_model):\n",
296296
" \"\"\"Pretty-prints an optimal assignment schedule\"\"\"\n",
297-
" client = opvious.Client.default(\"https://try.opvious.io\")\n",
297+
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
298298
" problem = opvious.Problem(\n",
299299
" specification=Scheduling(shifts_model).specification(),\n",
300300
" parameters={\n",

resources/examples/fantasy-premier-league.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@
438438
"import opvious\n",
439439
"import pandas as pd\n",
440440
"\n",
441-
"_client = opvious.Client.default(\"https://try.opvious.io\", token=None) # Replace `None` with your API access token\n",
441+
"_client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
442442
"\n",
443443
"async def find_optimal_squad(\n",
444444
" substitution_factor=0.1,\n",

resources/examples/job-shop-scheduling.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@
161161
" 'dependency': [(str(k), str(v['prec'])) for k, v in tasks.items() if v['prec']]\n",
162162
" },\n",
163163
" )\n",
164-
" solution = await opvious.Client.default(\"https://try.opvious.io\").solve(problem)\n",
164+
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
165+
" solution = await client.solve(problem)\n",
165166
" return solution.outputs.variable('taskStart')"
166167
]
167168
},

resources/examples/lot-sizing.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@
146146
" 'horizon': len(inputs_df),\n",
147147
" },\n",
148148
" )\n",
149-
" solution = await opvious.Client.default(\"https://try.opvious.io\").solve(problem)\n",
149+
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
150+
" solution = await client.solve(problem)\n",
150151
" return solution.outputs.variable('production').sort_index()"
151152
]
152153
},

resources/examples/portfolio-optimization.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@
434434
" 'minimumAllocation': {},\n",
435435
" },\n",
436436
" )\n",
437-
" solution = await opvious.Client.default(\"https://try.opvious.io\").solve(problem)\n",
437+
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
438+
" solution = await client.solve(problem)\n",
438439
" allocation = solution.outputs.variable('allocation')\n",
439440
" return allocation.reset_index(names=['ticker']).join(\n",
440441
" returns_df.agg(['mean', 'var']).T,\n",

resources/examples/product-allocation.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
"import opvious\n",
169169
"import pandas as pd\n",
170170
"\n",
171-
"client = opvious.Client.default(\"https://try.opvious.io\")"
171+
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n"
172172
]
173173
},
174174
{

resources/examples/sudoku.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
" .pivot_table(index='row', columns='column', values='value')\n",
6565
" .reindex(positions)\n",
6666
" .reindex(positions, axis=1)\n",
67-
" .applymap(lambda v: str(int(v)) if v == v else '')\n",
67+
" .map(lambda v: str(int(v)) if v == v else '')\n",
6868
" )"
6969
]
7070
},
@@ -192,7 +192,7 @@
192192
"source": [
193193
"import opvious\n",
194194
"\n",
195-
"client = opvious.Client.default(\"https://try.opvious.io\")\n",
195+
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
196196
"\n",
197197
"async def fill_in(grid):\n",
198198
" \"\"\"Completes a partial grid into a valid solution\n",

resources/guides/managing-modeling-complexity.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
"source": [
309309
"import opvious\n",
310310
"\n",
311-
"client = opvious.Client.default(\"https://try.opvious.io\")\n",
311+
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
312312
"\n",
313313
"annotated = await client.annotate_specification(Invalid().specification())\n",
314314
"annotated"

resources/guides/uploading-a-model.ipynb

+8-7
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@
9696
"source": [
9797
"import opvious\n",
9898
"\n",
99-
"OPVIOUS_TOKEN = '' # Enter your API token here\n",
100-
"\n",
101-
"client = opvious.Client.default(\"https://try.opvious.io\", token=OPVIOUS_TOKEN)\n",
99+
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
102100
"\n",
103101
"FORMULATION_NAME = \"bin-packing\"\n",
104102
"\n",
@@ -167,7 +165,7 @@
167165
"id": "ddb53774-b219-4a22-8d80-8f85224bc6e5",
168166
"metadata": {},
169167
"source": [
170-
"We can also make requests without the SDK: under the hood everything goes through the same API (see its OpenAPI specification [here](https://api.cloud.opvious.io/openapi.yaml)). To show how, we implement below a function which returns the minimum number of bins needed to fit the input items (our model's objective value) using the popular `requests` library."
168+
"We can also make requests without the SDK: under the hood everything goes through the same API (see its OpenAPI specification [here](https://api.try.opvious.io/openapi.yaml)). To show how, we implement below a function which returns the minimum number of bins needed to fit the input items (our model's objective value) using the popular `requests` library."
171169
]
172170
},
173171
{
@@ -198,8 +196,11 @@
198196
}
199197
],
200198
"source": [
199+
"import os\n",
201200
"import requests\n",
202201
"\n",
202+
"_token = os.environ.get('OPVIOUS_TOKEN')\n",
203+
"\n",
203204
"def minimum_bin_count(bin_max_weight, item_weights, version_tag='latest'):\n",
204205
" \"\"\"Returns the minimum number of bins needed to fit the input items\n",
205206
"\n",
@@ -209,10 +210,10 @@
209210
" version_tag: Model version tag\n",
210211
" \"\"\"\n",
211212
" response = requests.post(\n",
212-
" url='https://api.cloud.opvious.io/solve',\n",
213+
" url=f'{client.executor.endpoint}/solve',\n",
213214
" headers={\n",
214215
" 'accept': 'application/json',\n",
215-
" 'authorization': f'Bearer {OPVIOUS_TOKEN}',\n",
216+
" 'authorization': f'Bearer {_token}',\n",
216217
" },\n",
217218
" json={\n",
218219
" 'problem': {\n",
@@ -228,7 +229,7 @@
228229
" )\n",
229230
" return response.json()['outcome']['objectiveValue']\n",
230231
"\n",
231-
"if OPVIOUS_TOKEN:\n",
232+
"if _token:\n",
232233
" minimum_bin_count(15, {\n",
233234
" 'light': 5,\n",
234235
" 'medium': 10,\n",

resources/guides/welcome.ipynb

+16-8
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 1,
23+
"execution_count": 8,
2424
"id": "d5a782a8",
2525
"metadata": {},
26-
"outputs": [],
26+
"outputs": [
27+
{
28+
"name": "stdout",
29+
"output_type": "stream",
30+
"text": [
31+
"Note: you may need to restart the kernel to use updated packages.\n"
32+
]
33+
}
34+
],
2735
"source": [
2836
"%pip install opvious"
2937
]
@@ -47,7 +55,7 @@
4755
},
4856
{
4957
"cell_type": "code",
50-
"execution_count": 2,
58+
"execution_count": 1,
5159
"id": "4ed1667e",
5260
"metadata": {},
5361
"outputs": [],
@@ -89,7 +97,7 @@
8997
},
9098
{
9199
"cell_type": "code",
92-
"execution_count": 3,
100+
"execution_count": 2,
93101
"id": "06d04aff",
94102
"metadata": {},
95103
"outputs": [
@@ -142,7 +150,7 @@
142150
},
143151
{
144152
"cell_type": "code",
145-
"execution_count": 4,
153+
"execution_count": 3,
146154
"id": "ad50096f",
147155
"metadata": {},
148156
"outputs": [],
@@ -169,7 +177,7 @@
169177
},
170178
{
171179
"cell_type": "code",
172-
"execution_count": 5,
180+
"execution_count": 4,
173181
"id": "c1dd5859",
174182
"metadata": {},
175183
"outputs": [
@@ -185,7 +193,7 @@
185193
}
186194
],
187195
"source": [
188-
"client = opvious.Client.default(\"https://try.opvious.io\")\n",
196+
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
189197
"\n",
190198
"async def solve_problem(problem):\n",
191199
" \"\"\"Returns an optimal set of projects for the provided budget allocation problem\"\"\"\n",
@@ -211,7 +219,7 @@
211219
},
212220
{
213221
"cell_type": "code",
214-
"execution_count": 6,
222+
"execution_count": 5,
215223
"id": "71e1ca5d",
216224
"metadata": {},
217225
"outputs": [

resources/templates/simple.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"source": [
8080
"import opvious\n",
8181
"\n",
82-
"client = opvious.Client.default(\"https://try.opvious.io\")\n",
82+
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
8383
"\n",
8484
"def build_problem(): # Add model-specific arguments\n",
8585
" \"\"\"Generates a problem instance from model-specific arguments\"\"\"\n",

0 commit comments

Comments
 (0)