-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from NSLS-II-PDF/offline-testing
Offline testing
- Loading branch information
Showing
3 changed files
with
173 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Example agent invesitgation\n", | ||
"This mimics the scripts in `pdf_agents/startup_scripts` with minimal and perhaps broken functionality due to a lack of redis, tiled, kafka, etc. \n", | ||
"\n", | ||
"It doesn't look at what an **exact** agent **did**, but what a type of agent **might do**.\n", | ||
"\n", | ||
"Recreations of other agents could be attempted by following a similar approach. As such multiple agents are shown in the cells below. " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys\n", | ||
"\n", | ||
"sys.path.append(\"../../\")\n", | ||
"import pandas as pd\n", | ||
"import numpy as np\n", | ||
"from pdf_agents.scientific_value import ScientificValueAgentBase\n", | ||
"from pdf_agents.sklearn import ActiveKmeansAgent" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Choose your fighter" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"### GP driven Baysian optimization of a scientific value function ###\n", | ||
"# agent = ScientificValueAgentBase(bounds=[-12.0, 46.0], ask_on_tell=False, report_on_tell=False, offline=True)\n", | ||
"### GP driven Baysian optimization of a scientific value function ###\n", | ||
"\n", | ||
"### KMeans driven selection of interesting points for XAFS beamline. ###\n", | ||
"## This skips over the MonarchSubject businsiness, and uses the same approach for driving a single beamline\n", | ||
"agent = ActiveKmeansAgent(\n", | ||
" k_clusters=4, bounds=[-12.0, 46.0], ask_on_tell=False, report_on_tell=False, offline=True\n", | ||
")\n", | ||
"### KMeans driven selection of interesting points for XAFS beamline. ###" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Load and tell the agent about data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = pd.read_pickle(\"~/Downloads/sim_pdf_df_020pts.pckl\")\n", | ||
"independent_vars = df.columns.to_numpy()\n", | ||
"observables = df.to_numpy().T" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"agent.tell_many(independent_vars, observables)\n", | ||
"for x in independent_vars:\n", | ||
" # This is done because the tell is happening without UIDs.\n", | ||
" agent.tell_cache.append(x)" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Ask the agent what it would do next\n", | ||
"\n", | ||
"- Kmeans agents can suggest multiple points\n", | ||
"- The GP Bayesopt agents are designed to suggest one at a time. \n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# docs, suggestions = agent.ask(1) # The argument here is batch size/number of suggestions\n", | ||
"docs, suggestions = agent.ask(4)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"docs" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"suggestions" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.12" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters