Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions anaconda-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ env_specs:
wxyz-demo:
packages:
- bqplot
- cycler
- dask
- dask >=0.18.2
- dask-ml
Expand All @@ -48,9 +49,11 @@ env_specs:
- jsonpointer
- jupyterlab >=0.35,<0.36
- lime
- matplotlib
- nodejs >=8.11,<9
- pip
- py-xgboost
- pygraphviz
- pyld
- python >=3.7,<3.8
- pyyaml
Expand All @@ -60,10 +63,9 @@ env_specs:
- skrebate
- tornado <6
- tpot
- xgboost
- matplotlib
- transitions
- umap-learn
- cycler
- xgboost
- pip:
- yellowbrick
channels:
Expand Down
1 change: 1 addition & 0 deletions ci/steps.conda.lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ steps:
python>=3.7,<3.8.0a0
pyyaml
traittypes
transitions
1 change: 1 addition & 0 deletions ci/steps.conda.nbtest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ steps:
tornado<6
tpot
traittypes
transitions
umap-learn

- script: python -m pip install --no-deps yellowbrick
Expand Down
7 changes: 4 additions & 3 deletions ci/steps.conda.robot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ steps:
dask
dask-ml
distributed
geckodriver
importnb
ipympl
ipywidgets
Expand All @@ -31,17 +32,17 @@ steps:
pylint
python>=3.7,<3.8.0a0
pyyaml
robotframework
robotframework-seleniumlibrary
scikit-image
scikit-learn
scikit-mdr
skrebate
tornado<6
tpot
traittypes
transitions
umap-learn
robotframework
robotframework-seleniumlibrary
geckodriver

- ${{ if eq(parameters.name, 'Windows') }}:
- script: python -m pip uninstall -y pyzmq && python -m pip install pyzmq
Expand Down
8 changes: 5 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ channels:

dependencies:
- bqplot
- cycler
- dask
- dask >=0.18.2
- dask-ml
Expand All @@ -16,9 +17,11 @@ dependencies:
- jsonpointer
- jupyterlab >=0.35,<0.36
- lime
- matplotlib
- nodejs >=8.11,<9
- pip
- py-xgboost
- pygraphviz
- pyld
- python >=3.7,<3.8
- pyyaml
Expand All @@ -28,9 +31,8 @@ dependencies:
- skrebate
- tornado <6
- tpot
- xgboost
- matplotlib
- transitions
- umap-learn
- cycler
- xgboost
- pip:
- yellowbrick
153 changes: 153 additions & 0 deletions notebooks/Examples/StateMachine II.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# StateMachine II"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from wxyz.stm.widget_stm import StateMachine, W\n",
"from wxyz.lab.widget_dock import DockBox\n",
"from yaml import safe_load"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with __import__(\"importnb\").Notebook():\n",
" from StateMachine import make_an_adventure"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if __name__ == \"__main__\":\n",
" state_dict = safe_load(\"\"\"\n",
" jail:\n",
" _:\n",
" find_key: jail_has_key\n",
" sleep: jail\n",
" has_key:\n",
" _:\n",
" escape: town\n",
" town:\n",
" _:\n",
" steal_get_caught: jail\n",
" steal: town_has_coin\n",
" beg: town_has_coin\n",
" has_coin:\n",
" _:\n",
" buy_sword: town_has_gear_sword\n",
" buy_wand: town_has_gear_wand\n",
" has_gear:\n",
" _:\n",
" practice: town_has_gear\n",
" sword:\n",
" wand:\n",
" \"\"\")\n",
" display(state_dict)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def state_dict_to_state_transitions(state_dict, prefix=\"\", parents=[]):\n",
" states = []\n",
" transitions = []\n",
" for state, children in state_dict.items():\n",
" if state == \"_\":\n",
" for tx, tgt in children.items():\n",
" if prefix:\n",
" transitions += [\n",
" [tx, parents[-1], tgt]\n",
" ]\n",
" else:\n",
" transitions += [\n",
" [tx, state, tgt]\n",
" ]\n",
" else:\n",
" cs, ct = [], []\n",
" if children:\n",
" cs, ct = state_dict_to_state_transitions(children, f\"{prefix}{state}_\", [*parents, f\"{prefix}{state}\"])\n",
" if cs:\n",
" states += [\n",
" {\"name\": state, \"children\": cs}\n",
" ]\n",
" else:\n",
" states += [state]\n",
" transitions += ct\n",
" return states, transitions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if __name__ == \"__main__\":\n",
" states, transitions = state_dict_to_state_transitions(state_dict)\n",
" display(states, transitions)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if __name__ == \"__main__\":\n",
" stm, view = make_an_adventure(states=states, transitions=transitions, initial=\"jail\")\n",
" dock = DockBox(view.children, layout=dict(height=\"600px\"))\n",
"\n",
" @dock.on_displayed\n",
" def _on_displayed(_):\n",
" dock.dock_layout = {\n",
" 'type': 'split-area',\n",
" 'orientation': 'horizontal',\n",
" 'children': [\n",
" {'type': 'tab-area', 'widgets': [0], 'currentIndex': 0},\n",
" {'type': 'tab-area', 'widgets': [1], 'currentIndex': 0}\n",
" ], 'sizes': [0.3, 0.7]}\n",
" display(dock)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
137 changes: 137 additions & 0 deletions notebooks/Examples/StateMachine.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# StateMachine"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from wxyz.stm.widget_stm import StateMachine, GraphMachine, W\n",
"from wxyz.svg.widget_svg import SVGBox"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def show_a_state_switch(\n",
" states=[\"magic\", \"more_magic\"], \n",
" transitions=[\n",
" [\"switch\", \"magic\", \"more_magic\"],\n",
" [\"switch\", \"more_magic\", \"magic\"]\n",
" ],\n",
" machine_class=StateMachine,\n",
" **kwargs\n",
"):\n",
" stm = machine_class(states=states, transitions=transitions, **kwargs)\n",
" current = W.Text(description=\"State\", disabled=True)\n",
" buttons = [W.Button(description=t) for t in set([t for t, u, v in transitions])]\n",
" for btn in buttons:\n",
" @btn.on_click\n",
" def switch_left(btn):\n",
" try:\n",
" getattr(stm.model, btn.description)()\n",
" stm.error = \"\"\n",
" except Exception as err:\n",
" stm.error = str(err)\n",
" err = W.HTML()\n",
" W.dlink((stm, \"state\"), (current, \"value\"))\n",
" W.dlink((stm, \"error\"), (err, \"value\"), \"<blockquote>{}</blockquote>\".format)\n",
" view = W.VBox([current, *buttons, err])\n",
" return stm, view"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if __name__ == \"__main__\":\n",
" stm, stm_view = show_a_state_switch()\n",
" display(stm_view)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def make_an_adventure(\n",
" states=[\"Floor\", \"Pit\", \"Ladder\"],\n",
" transitions = [\n",
" [\"fall\", \"Floor\", \"Pit\"],\n",
" [\"sleep\", \"Pit\", \"Pit\"],\n",
" [\"sleep\", \"Floor\", \"Floor\"],\n",
" [\"climb\", \"Pit\", \"Ladder\"],\n",
" [\"climb\", \"Ladder\", \"Floor\"]\n",
" ],\n",
" machine_class=GraphMachine,\n",
" **kwargs\n",
"):\n",
" stm2, view = show_a_state_switch(states, transitions, machine_class=GraphMachine, **kwargs)\n",
" svg = SVGBox(show_svg=True, area_attr=\"id\", visible_areas=[\"*\"])\n",
" W.dlink((stm2, \"svg\"), (svg, \"svg\"))\n",
" prog = W.SelectionSlider(options=[\"dot\", \"neato\", \"circo\", \"fdp\"],\n",
" description=\"Layout\")\n",
" W.link([prog, \"value\"], [stm2, \"prog\"])\n",
" return stm2, W.HBox([\n",
" W.VBox([\n",
" view,\n",
" prog\n",
" ]),\n",
" svg\n",
" ])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"if __name__ == \"__main__\":\n",
" stm2, view2 = make_an_adventure()\n",
" display(view2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading