diff --git a/.github/workflows/check-compatibility.yml b/.github/workflows/check-compatibility.yml index e6767ea..708f1ed 100644 --- a/.github/workflows/check-compatibility.yml +++ b/.github/workflows/check-compatibility.yml @@ -10,8 +10,8 @@ on: - main paths-ignore: - '**/README.md' - schedule: - - cron: '5 */8 * * *' + # schedule: + # - cron: '5 */8 * * *' workflow_dispatch: {} jobs: image-api: diff --git a/requirements.txt b/requirements.txt index 976d6a4..04dfccb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Aggregated requirements from all notebooks -opvious[aio,cli]>=0.18.2 +opvious[aio,cli]>=0.20 pandas requests yfinance diff --git a/resources/examples/bin-packing.ipynb b/resources/examples/bin-packing.ipynb index ebf910b..14c5d70 100644 --- a/resources/examples/bin-packing.ipynb +++ b/resources/examples/bin-packing.ipynb @@ -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))" ] diff --git a/resources/examples/consecutive-shift-scheduling.ipynb b/resources/examples/consecutive-shift-scheduling.ipynb index c6a8f7f..2bbcdd9 100644 --- a/resources/examples/consecutive-shift-scheduling.ipynb +++ b/resources/examples/consecutive-shift-scheduling.ipynb @@ -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", diff --git a/resources/examples/debt-simplification.ipynb b/resources/examples/debt-simplification.ipynb index 0689923..ac4ea83 100644 --- a/resources/examples/debt-simplification.ipynb +++ b/resources/examples/debt-simplification.ipynb @@ -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)" ] }, diff --git a/resources/examples/doctor-scheduling.ipynb b/resources/examples/doctor-scheduling.ipynb index 972ab7d..6682c97 100644 --- a/resources/examples/doctor-scheduling.ipynb +++ b/resources/examples/doctor-scheduling.ipynb @@ -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", diff --git a/resources/examples/fantasy-premier-league.ipynb b/resources/examples/fantasy-premier-league.ipynb index 8a3a1de..cfb2fac 100644 --- a/resources/examples/fantasy-premier-league.ipynb +++ b/resources/examples/fantasy-premier-league.ipynb @@ -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", diff --git a/resources/examples/job-shop-scheduling.ipynb b/resources/examples/job-shop-scheduling.ipynb index 521fdc9..5b66440 100644 --- a/resources/examples/job-shop-scheduling.ipynb +++ b/resources/examples/job-shop-scheduling.ipynb @@ -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')" ] }, diff --git a/resources/examples/lot-sizing.ipynb b/resources/examples/lot-sizing.ipynb index b55bcb4..0659ace 100644 --- a/resources/examples/lot-sizing.ipynb +++ b/resources/examples/lot-sizing.ipynb @@ -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()" ] }, diff --git a/resources/examples/portfolio-optimization.ipynb b/resources/examples/portfolio-optimization.ipynb index 3d213c3..04ca8c3 100644 --- a/resources/examples/portfolio-optimization.ipynb +++ b/resources/examples/portfolio-optimization.ipynb @@ -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", diff --git a/resources/examples/product-allocation.ipynb b/resources/examples/product-allocation.ipynb index e3e562e..9cc74e7 100644 --- a/resources/examples/product-allocation.ipynb +++ b/resources/examples/product-allocation.ipynb @@ -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" ] }, { diff --git a/resources/examples/sudoku.ipynb b/resources/examples/sudoku.ipynb index 30373cf..276e357 100644 --- a/resources/examples/sudoku.ipynb +++ b/resources/examples/sudoku.ipynb @@ -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", " )" ] }, @@ -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", diff --git a/resources/guides/managing-modeling-complexity.ipynb b/resources/guides/managing-modeling-complexity.ipynb index 8ce1c36..d3be341 100644 --- a/resources/guides/managing-modeling-complexity.ipynb +++ b/resources/guides/managing-modeling-complexity.ipynb @@ -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" diff --git a/resources/guides/uploading-a-model.ipynb b/resources/guides/uploading-a-model.ipynb index a2d8f2c..241c55d 100644 --- a/resources/guides/uploading-a-model.ipynb +++ b/resources/guides/uploading-a-model.ipynb @@ -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", @@ -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." ] }, { @@ -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", @@ -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", @@ -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", diff --git a/resources/guides/welcome.ipynb b/resources/guides/welcome.ipynb index bf9d754..4d10b77 100644 --- a/resources/guides/welcome.ipynb +++ b/resources/guides/welcome.ipynb @@ -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" ] @@ -47,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "4ed1667e", "metadata": {}, "outputs": [], @@ -89,7 +97,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "id": "06d04aff", "metadata": {}, "outputs": [ @@ -142,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "id": "ad50096f", "metadata": {}, "outputs": [], @@ -169,7 +177,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "id": "c1dd5859", "metadata": {}, "outputs": [ @@ -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", @@ -211,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "id": "71e1ca5d", "metadata": {}, "outputs": [ diff --git a/resources/templates/simple.ipynb b/resources/templates/simple.ipynb index 426c368..e1cc897 100644 --- a/resources/templates/simple.ipynb +++ b/resources/templates/simple.ipynb @@ -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",