From b4e3c9aeab8f1cc9fca026cead76d631323ffb5b Mon Sep 17 00:00:00 2001 From: John Gerrard Holland Date: Thu, 6 Jul 2023 10:45:29 -0400 Subject: [PATCH] docs: update examples of using state dependent properties --- ...Accessing State Dependent Properties.ipynb | 119 +++++++++++++++++- 1 file changed, 116 insertions(+), 3 deletions(-) diff --git a/docs/interactive/Accessing State Dependent Properties.ipynb b/docs/interactive/Accessing State Dependent Properties.ipynb index 24f4c612..c5f715c1 100644 --- a/docs/interactive/Accessing State Dependent Properties.ipynb +++ b/docs/interactive/Accessing State Dependent Properties.ipynb @@ -120,7 +120,50 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
x
02
\n", + "
" + ], + "text/plain": [ + " x\n", + "0 2" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "cycle_with_state_dep_properties.run().data.conditions[-1]" ] @@ -136,7 +179,50 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
x
01
\n", + "
" + ], + "text/plain": [ + " x\n", + "0 1" + ] + }, + "execution_count": null, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "cycle_with_state_dep_properties.run(num_cycles=9).data.conditions[-1]" ] @@ -153,10 +239,37 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ValueError", + "evalue": "a cannot be empty unless no samples are taken", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[6], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mcycle_with_state_dep_properties\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Developer/autora-workflow/src/autora/workflow/cycle.py:82\u001b[0m, in \u001b[0;36mCycle.run\u001b[0;34m(self, num_cycles)\u001b[0m\n\u001b[1;32m 80\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mrun\u001b[39m(\u001b[38;5;28mself\u001b[39m, num_cycles: \u001b[38;5;28mint\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m):\n\u001b[1;32m 81\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Execute the next step in the cycle.\"\"\"\u001b[39;00m\n\u001b[0;32m---> 82\u001b[0m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43mnum_steps\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnum_cycles\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 83\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\n", + "File \u001b[0;32m~/Developer/autora-workflow/src/autora/workflow/base.py:85\u001b[0m, in \u001b[0;36mBaseController.run\u001b[0;34m(self, num_steps)\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"Run the next num_steps planned steps in the workflow.\"\"\"\u001b[39;00m\n\u001b[1;32m 84\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(num_steps):\n\u001b[0;32m---> 85\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun_once\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 86\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\n", + "File \u001b[0;32m~/Developer/autora-workflow/src/autora/workflow/base.py:71\u001b[0m, in \u001b[0;36mBaseController.run_once\u001b[0;34m(self, step_name)\u001b[0m\n\u001b[1;32m 68\u001b[0m _logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mnext_params\u001b[38;5;132;01m=}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 70\u001b[0m \u001b[38;5;66;03m# Execute\u001b[39;00m\n\u001b[0;32m---> 71\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mnext_function\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstate\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnext_params\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 72\u001b[0m _logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresult\u001b[38;5;132;01m=}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 74\u001b[0m \u001b[38;5;66;03m# Update\u001b[39;00m\n", + "File \u001b[0;32m~/Developer/autora-workflow/src/autora/workflow/executor.py:174\u001b[0m, in \u001b[0;36mfull_cycle_wrapper.._executor_full_cycle\u001b[0;34m(state, params)\u001b[0m\n\u001b[1;32m 169\u001b[0m experimentalist_params \u001b[38;5;241m=\u001b[39m params\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mexperimentalist\u001b[39m\u001b[38;5;124m\"\u001b[39m, {})\n\u001b[1;32m 171\u001b[0m experimentalist_executor \u001b[38;5;241m=\u001b[39m from_experimentalist_pipeline(\n\u001b[1;32m 172\u001b[0m experimentalist_pipeline\n\u001b[1;32m 173\u001b[0m )\n\u001b[0;32m--> 174\u001b[0m experimentalist_result \u001b[38;5;241m=\u001b[39m \u001b[43mexperimentalist_executor\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstate\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexperimentalist_params\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 176\u001b[0m experiment_runner_params \u001b[38;5;241m=\u001b[39m params\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mexperiment_runner\u001b[39m\u001b[38;5;124m\"\u001b[39m, {})\n\u001b[1;32m 177\u001b[0m experiment_runner_executor \u001b[38;5;241m=\u001b[39m from_experiment_runner_callable(\n\u001b[1;32m 178\u001b[0m experiment_runner_callable\n\u001b[1;32m 179\u001b[0m )\n", + "File \u001b[0;32m~/Developer/autora-workflow/src/autora/workflow/executor.py:64\u001b[0m, in \u001b[0;36mfrom_experimentalist_pipeline.._executor_experimentalist\u001b[0;34m(state, params)\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_executor_experimentalist\u001b[39m(state: SupportsControllerState, params: Dict):\n\u001b[1;32m 63\u001b[0m params_ \u001b[38;5;241m=\u001b[39m resolve_state_params(params, state)\n\u001b[0;32m---> 64\u001b[0m new_conditions \u001b[38;5;241m=\u001b[39m \u001b[43mpipeline\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mparams_\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 66\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(new_conditions, pd\u001b[38;5;241m.\u001b[39mDataFrame):\n\u001b[1;32m 67\u001b[0m new_conditions_array \u001b[38;5;241m=\u001b[39m new_conditions\n", + "File \u001b[0;32m~/Developer/autora-workflow/.venv/lib/python3.8/site-packages/autora/experimentalist/pipeline.py:171\u001b[0m, in \u001b[0;36mPipeline.__call__\u001b[0;34m(self, ex, **params)\u001b[0m\n\u001b[1;32m 169\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(pipe, Pipe)\n\u001b[1;32m 170\u001b[0m all_params_for_pipe \u001b[38;5;241m=\u001b[39m merged_params\u001b[38;5;241m.\u001b[39mget(name, \u001b[38;5;28mdict\u001b[39m())\n\u001b[0;32m--> 171\u001b[0m results\u001b[38;5;241m.\u001b[39mappend(\u001b[43mpipe\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresults\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mall_params_for_pipe\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 173\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m results[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m]\n", + "Cell \u001b[0;32mIn[3], line 9\u001b[0m, in \u001b[0;36mcustom_random_sampler\u001b[0;34m(conditions, n)\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcustom_random_sampler\u001b[39m(conditions, n):\n\u001b[0;32m----> 9\u001b[0m sampled_conditions \u001b[38;5;241m=\u001b[39m \u001b[43mrandom_sampler_rng\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mchoice\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconditions\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msize\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mn\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mreplace\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m sampled_conditions\n", + "File \u001b[0;32m_generator.pyx:729\u001b[0m, in \u001b[0;36mnumpy.random._generator.Generator.choice\u001b[0;34m()\u001b[0m\n", + "\u001b[0;31mValueError\u001b[0m: a cannot be empty unless no samples are taken" + ] + } + ], "source": [ "cycle_with_state_dep_properties.run()\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {