Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable tutorials on Windows #259

Draft
wants to merge 50 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f456afb
- Initial enablement of RefPort and VarPorts
PhilippPlank Nov 12, 2021
2d0ec74
- Initial enablement of RefPort and VarPorts
PhilippPlank Nov 12, 2021
25a3a68
- Initial enablement of RefPort and VarPorts
PhilippPlank Nov 12, 2021
a2d1765
- Initial enablement of RefPort and VarPorts
PhilippPlank Nov 12, 2021
74dfdf6
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 15, 2021
1daa9af
- Enablement of RefPorts and VarPorts - addressed change requests fro…
PhilippPlank Nov 16, 2021
5908401
- Enablement of RefPorts and VarPorts - addressed change requests fro…
PhilippPlank Nov 16, 2021
3df2847
- Enablement of RefPorts and VarPorts - addressed change requests fro…
PhilippPlank Nov 16, 2021
9581fae
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 16, 2021
6e4716a
- Enablement of RefPorts and VarPorts - addressed change requests fro…
PhilippPlank Nov 16, 2021
e22def6
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 17, 2021
bd25a80
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 17, 2021
7edeb1f
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 18, 2021
23fb8d7
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 18, 2021
f6686b4
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 23, 2021
86867c2
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 23, 2021
859a195
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 24, 2021
f7007f8
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 25, 2021
0163202
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 25, 2021
bf934ef
modified connection tutorial for release 0.2.0
PhilippPlank Nov 26, 2021
0eef67e
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 26, 2021
f08a35c
fixed typos
PhilippPlank Nov 26, 2021
ceddf2a
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 26, 2021
f798b0a
Merge branch 'lava-nc:main' into main
PhilippPlank Nov 30, 2021
b6e72bb
Merge branch 'lava-nc:main' into main
PhilippPlank Dec 1, 2021
9c57309
Merge branch 'lava-nc:main' into main
PhilippPlank Dec 3, 2021
7425f7e
Merge branch 'lava-nc:main' into main
PhilippPlank Dec 6, 2021
bc353c7
Merge branch 'lava-nc:main' into main
PhilippPlank Jan 27, 2022
73288a4
Merge branch 'lava-nc:main' into main
PhilippPlank Jan 31, 2022
3f5c2d7
Merge branch 'lava-nc:main' into main
PhilippPlank Feb 9, 2022
e691b1d
Merge branch 'lava-nc:main' into main
PhilippPlank Feb 10, 2022
9ab9a5d
Merge branch 'lava-nc:main' into main
PhilippPlank Feb 10, 2022
a1f0367
Merge branch 'lava-nc:main' into main
PhilippPlank Feb 16, 2022
50f9113
Merge branch 'lava-nc:main' into main
PhilippPlank Feb 16, 2022
e2342f5
Merge branch 'lava-nc:main' into main
PhilippPlank Feb 24, 2022
0b7cedb
Merge branch 'lava-nc:main' into main
PhilippPlank Feb 24, 2022
6a30ad7
Merge branch 'lava-nc:main' into main
PhilippPlank Feb 25, 2022
8e652bc
Merge branch 'lava-nc:main' into main
PhilippPlank Feb 25, 2022
3b3cc6f
Merge branch 'lava-nc:main' into main
PhilippPlank Mar 2, 2022
46b54ad
Merge branch 'lava-nc:main' into main
PhilippPlank Mar 3, 2022
0c02489
Merge branch 'lava-nc:main' into main
PhilippPlank Mar 4, 2022
01d9097
Merge branch 'lava-nc:main' into main
PhilippPlank Mar 11, 2022
efc0bd4
Merge branch 'lava-nc:main' into main
PhilippPlank Mar 16, 2022
976c5d2
Merge branch 'lava-nc:main' into main
PhilippPlank Jun 9, 2022
e4c54c2
Merge branch 'lava-nc:main' into main
PhilippPlank Jun 11, 2022
f881ef2
Merge branch 'lava-nc:main' into tutorial_win_fix
PhilippPlank Jun 14, 2022
be9aa26
Windows fix for tutorials - draft
PhilippPlank Jun 14, 2022
b89d6f1
moved win_exec.py to utils and changed text
weidel-p Jun 16, 2022
b397080
used magic to export single cells instead of complete script
weidel-p Jun 16, 2022
771ae85
lint
weidel-p Jun 27, 2022
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
92 changes: 82 additions & 10 deletions tutorials/in_depth/tutorial02_processes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "685af4da",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -165,7 +165,35 @@
"execution_count": 2,
"id": "bb4835e1",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\pplank\\AppData\\Local\\Temp\\ipykernel_3388\\2851907654.py:13: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" a_in: PyInPort = LavaPyType(PyInPort.VEC_DENSE, np.float)\n",
"C:\\Users\\pplank\\AppData\\Local\\Temp\\ipykernel_3388\\2851907654.py:15: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" u: np.ndarray = LavaPyType(np.ndarray, np.float)\n",
"C:\\Users\\pplank\\AppData\\Local\\Temp\\ipykernel_3388\\2851907654.py:16: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" v: np.ndarray = LavaPyType(np.ndarray, np.float)\n",
"C:\\Users\\pplank\\AppData\\Local\\Temp\\ipykernel_3388\\2851907654.py:17: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" bias: np.ndarray = LavaPyType(np.ndarray, np.float)\n",
"C:\\Users\\pplank\\AppData\\Local\\Temp\\ipykernel_3388\\2851907654.py:18: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" du: float = LavaPyType(float, np.float)\n",
"C:\\Users\\pplank\\AppData\\Local\\Temp\\ipykernel_3388\\2851907654.py:19: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" dv: float = LavaPyType(float, np.float)\n",
"C:\\Users\\pplank\\AppData\\Local\\Temp\\ipykernel_3388\\2851907654.py:20: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
" vth: float = LavaPyType(float, np.float)\n"
]
}
],
"source": [
"import numpy as np\n",
"from lava.magma.core.sync.protocols.loihi_protocol import LoihiProtocol\n",
Expand Down Expand Up @@ -199,6 +227,31 @@
" self.s_out.send(s_out)"
]
},
{
"cell_type": "markdown",
"id": "e62a6fd4",
"metadata": {},
"source": [
"#### Exception for Windows\n",
"\n",
"The next cell is only needed for systems running on Windows. This is not part of the tutorial or Lava, but to allow this jupyter notebook to execute on Windows without errors. The class LIF and PyLifModel need to be imported from a script in order to run this tutorial on Windows due to an issue with the multiprocessing package on Windows. Therefore we create a python script from this jupyter notebook and import the classes defined above from there.\n",
"With this solution you can still modify the classes above and rerun the notebook to see the changes!"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2a1837e9",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"from win_exec import enable_win, cleanup\n",
"enable_win(\"tutorial02_processes\")\n",
"from tutorial02_processes import LIF"
]
},
{
"cell_type": "markdown",
"id": "a27ae936",
Expand All @@ -211,7 +264,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"id": "2d14869c",
"metadata": {},
"outputs": [],
Expand All @@ -237,7 +290,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"id": "27e749ec",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -273,7 +326,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "6ae84fef",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -309,7 +362,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "f25e0cd9",
"metadata": {},
"outputs": [],
Expand All @@ -330,7 +383,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"id": "110b9196",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -358,7 +411,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"id": "4cb4d6bb",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -389,7 +442,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"id": "31b51fb7",
"metadata": {},
"outputs": [],
Expand All @@ -410,6 +463,25 @@
"\n",
"To receive regular updates on the latest developments and releases of the Lava Software Framework please subscribe to the [INRC newsletter](http://eepurl.com/hJCyhb \"INRC Newsletter\")."
]
},
{
"cell_type": "markdown",
"id": "663b1e84",
"metadata": {},
"source": [
"#### Exception for Windows\n",
"Delete the created python script again."
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "326cc579",
"metadata": {},
"outputs": [],
"source": [
"cleanup(\"tutorial02_processes\")"
]
}
],
"metadata": {
Expand All @@ -428,7 +500,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.9.13"
}
},
"nbformat": 4,
Expand Down
37 changes: 37 additions & 0 deletions tutorials/in_depth/win_exec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (C) 2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
# See: https://spdx.org/licenses/

from sys import platform
import os


def enable_win(nb_name: str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please come up with a better name.

"""Enables execution of Lava tutorials on Windows systems. Processes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please give better justification for this workaround.
Provide a bit of context why such a strange hack is necessary. If people are not just told what is done by why it is done, it's easier to "accept".

defined within the tutorial jupyter notebook need to be written to a python
script and imported in the notebook again."""
if platform == "win32" or platform == "cygwin":
# Convert the ipython notebook to a python script
os.system("jupyter nbconvert --to script " + nb_name + ".ipynb")

# Remove code after definition to avoid execution during import
with open(nb_name + ".py", "r+") as f:
d = f.readlines()
f.seek(0)
for i in d:
if i.strip("\n") != "# #### Exception for Windows":
f.write(i)
elif i.strip("\n") == "# #### Exception for Windows":
break
f.truncate()


def cleanup(nb_name: str):
"""Removes previously created python script for tutorial execution on
Windows systems."""
if platform == "win32" or platform == "cygwin":
os.system("del " + nb_name + ".py")


if __name__ == "__main__":
pass