Skip to content

Commit

Permalink
feat: switch to new demo endpoint (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtth authored Sep 8, 2024
1 parent a176139 commit fcc9136
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ on:
- main
paths-ignore:
- '**/README.md'
schedule:
- cron: '5 */8 * * *'
# schedule:
# - cron: '5 */8 * * *'
workflow_dispatch: {}
jobs:
image-api:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Aggregated requirements from all notebooks
opvious[aio,cli]>=0.18.2
opvious[aio,cli]>=0.20
pandas
requests
yfinance
3 changes: 2 additions & 1 deletion resources/examples/bin-packing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@
" specification=model.specification(),\n",
" parameters={'weight': item_weights, 'maxWeight': bin_max_weight},\n",
" )\n",
" solution = await opvious.Client.default().solve(problem)\n",
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
" solution = await client.solve(problem)\n",
" assignment = solution.outputs.variable('assigned')\n",
" return list(assignment.reset_index().groupby('bins')['items'].agg(tuple))"
]
Expand Down
2 changes: 1 addition & 1 deletion resources/examples/consecutive-shift-scheduling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
"\n",
"logging.basicConfig(level=logging.INFO)\n",
"\n",
"client = opvious.Client.default(\"https://try.opvious.io\") # Add a token argument here to run this from the browser\n",
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
"\n",
"# Store the formulation on the server to be able to queue a solve below\n",
"specification = await client.register_specification(model.specification(), \"consecutive-shift-scheduling\")\n",
Expand Down
3 changes: 2 additions & 1 deletion resources/examples/debt-simplification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@
" target='minimizeTotalTransferred', # Final target: minimize total transfer amount\n",
" ),\n",
" )\n",
" solution = await opvious.Client.default(\"https://try.opvious.io\").solve(problem)\n",
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
" solution = await client.solve(problem)\n",
" return solution.outputs.variable('transfer').unstack(level=1).fillna(0).round(2)"
]
},
Expand Down
2 changes: 1 addition & 1 deletion resources/examples/doctor-scheduling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
"\n",
"async def find_optimal_schedule(shifts_model):\n",
" \"\"\"Pretty-prints an optimal assignment schedule\"\"\"\n",
" client = opvious.Client.default(\"https://try.opvious.io\")\n",
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
" problem = opvious.Problem(\n",
" specification=Scheduling(shifts_model).specification(),\n",
" parameters={\n",
Expand Down
2 changes: 1 addition & 1 deletion resources/examples/fantasy-premier-league.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@
"import opvious\n",
"import pandas as pd\n",
"\n",
"_client = opvious.Client.default(\"https://try.opvious.io\", token=None) # Replace `None` with your API access token\n",
"_client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
"\n",
"async def find_optimal_squad(\n",
" substitution_factor=0.1,\n",
Expand Down
3 changes: 2 additions & 1 deletion resources/examples/job-shop-scheduling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@
" 'dependency': [(str(k), str(v['prec'])) for k, v in tasks.items() if v['prec']]\n",
" },\n",
" )\n",
" solution = await opvious.Client.default(\"https://try.opvious.io\").solve(problem)\n",
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
" solution = await client.solve(problem)\n",
" return solution.outputs.variable('taskStart')"
]
},
Expand Down
3 changes: 2 additions & 1 deletion resources/examples/lot-sizing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@
" 'horizon': len(inputs_df),\n",
" },\n",
" )\n",
" solution = await opvious.Client.default(\"https://try.opvious.io\").solve(problem)\n",
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
" solution = await client.solve(problem)\n",
" return solution.outputs.variable('production').sort_index()"
]
},
Expand Down
3 changes: 2 additions & 1 deletion resources/examples/portfolio-optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,8 @@
" 'minimumAllocation': {},\n",
" },\n",
" )\n",
" solution = await opvious.Client.default(\"https://try.opvious.io\").solve(problem)\n",
" client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
" solution = await client.solve(problem)\n",
" allocation = solution.outputs.variable('allocation')\n",
" return allocation.reset_index(names=['ticker']).join(\n",
" returns_df.agg(['mean', 'var']).T,\n",
Expand Down
2 changes: 1 addition & 1 deletion resources/examples/product-allocation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"import opvious\n",
"import pandas as pd\n",
"\n",
"client = opvious.Client.default(\"https://try.opvious.io\")"
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions resources/examples/sudoku.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
" .pivot_table(index='row', columns='column', values='value')\n",
" .reindex(positions)\n",
" .reindex(positions, axis=1)\n",
" .applymap(lambda v: str(int(v)) if v == v else '')\n",
" .map(lambda v: str(int(v)) if v == v else '')\n",
" )"
]
},
Expand Down Expand Up @@ -192,7 +192,7 @@
"source": [
"import opvious\n",
"\n",
"client = opvious.Client.default(\"https://try.opvious.io\")\n",
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
"\n",
"async def fill_in(grid):\n",
" \"\"\"Completes a partial grid into a valid solution\n",
Expand Down
2 changes: 1 addition & 1 deletion resources/guides/managing-modeling-complexity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
"source": [
"import opvious\n",
"\n",
"client = opvious.Client.default(\"https://try.opvious.io\")\n",
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
"\n",
"annotated = await client.annotate_specification(Invalid().specification())\n",
"annotated"
Expand Down
15 changes: 8 additions & 7 deletions resources/guides/uploading-a-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@
"source": [
"import opvious\n",
"\n",
"OPVIOUS_TOKEN = '' # Enter your API token here\n",
"\n",
"client = opvious.Client.default(\"https://try.opvious.io\", token=OPVIOUS_TOKEN)\n",
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
"\n",
"FORMULATION_NAME = \"bin-packing\"\n",
"\n",
Expand Down Expand Up @@ -167,7 +165,7 @@
"id": "ddb53774-b219-4a22-8d80-8f85224bc6e5",
"metadata": {},
"source": [
"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."
"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."
]
},
{
Expand Down Expand Up @@ -198,8 +196,11 @@
}
],
"source": [
"import os\n",
"import requests\n",
"\n",
"_token = os.environ.get('OPVIOUS_TOKEN')\n",
"\n",
"def minimum_bin_count(bin_max_weight, item_weights, version_tag='latest'):\n",
" \"\"\"Returns the minimum number of bins needed to fit the input items\n",
"\n",
Expand All @@ -209,10 +210,10 @@
" version_tag: Model version tag\n",
" \"\"\"\n",
" response = requests.post(\n",
" url='https://api.cloud.opvious.io/solve',\n",
" url=f'{client.executor.endpoint}/solve',\n",
" headers={\n",
" 'accept': 'application/json',\n",
" 'authorization': f'Bearer {OPVIOUS_TOKEN}',\n",
" 'authorization': f'Bearer {_token}',\n",
" },\n",
" json={\n",
" 'problem': {\n",
Expand All @@ -228,7 +229,7 @@
" )\n",
" return response.json()['outcome']['objectiveValue']\n",
"\n",
"if OPVIOUS_TOKEN:\n",
"if _token:\n",
" minimum_bin_count(15, {\n",
" 'light': 5,\n",
" 'medium': 10,\n",
Expand Down
24 changes: 16 additions & 8 deletions resources/guides/welcome.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 8,
"id": "d5a782a8",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install opvious"
]
Expand All @@ -47,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "4ed1667e",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -89,7 +97,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "06d04aff",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -142,7 +150,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "ad50096f",
"metadata": {},
"outputs": [],
Expand All @@ -169,7 +177,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"id": "c1dd5859",
"metadata": {},
"outputs": [
Expand All @@ -185,7 +193,7 @@
}
],
"source": [
"client = opvious.Client.default(\"https://try.opvious.io\")\n",
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
"\n",
"async def solve_problem(problem):\n",
" \"\"\"Returns an optimal set of projects for the provided budget allocation problem\"\"\"\n",
Expand All @@ -211,7 +219,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"id": "71e1ca5d",
"metadata": {},
"outputs": [
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/simple.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"source": [
"import opvious\n",
"\n",
"client = opvious.Client.default(\"https://try.opvious.io\")\n",
"client = opvious.Client.from_environment(default_endpoint=opvious.DEMO_ENDPOINT)\n",
"\n",
"def build_problem(): # Add model-specific arguments\n",
" \"\"\"Generates a problem instance from model-specific arguments\"\"\"\n",
Expand Down

0 comments on commit fcc9136

Please sign in to comment.