Skip to content

Commit

Permalink
Serialization (#76)
Browse files Browse the repository at this point in the history
* Cleanup Parameter cache

  - Make Parameter cache optional with "use_cache" keyword argument
  - Clear Parameter cache before and after solve avoid serializing the cache and writing it to disk
  - Disable use_cache by default for non-composite parameters

* Use numbers types and fix Parameter cache

* Update version.py

* Run notebooks
  • Loading branch information
loganbvh authored Apr 12, 2024
1 parent 29787af commit db30117
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 66 deletions.
6 changes: 3 additions & 3 deletions docs/notebooks/logo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Constructing Voronoi polygons: 100%|█████| 4084/4084 [00:00<00:00, 21530.56it/s]\n"
"Constructing Voronoi polygons: 100%|███████████████████████████████████████████████████████████████████| 4084/4084 [00:00<00:00, 22641.44it/s]\n"
]
},
{
Expand Down Expand Up @@ -276,7 +276,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Simulating: 100%|██████████████████████████▉| 800/800 [01:59<00:00, 6.70tau/s ]\n"
"Simulating: 100%|████████████████████████████████████████████████████████████████████████████████████████▉| 800/800 [12:35<00:00, 1.06tau/s ]\n"
]
}
],
Expand Down Expand Up @@ -8699,7 +8699,7 @@
{
"data": {
"text/html": [
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>tdgl</td><td>0.8.1; git revision 268e366 [2024-01-30]</td></tr><tr><td>Numpy</td><td>1.24.3</td></tr><tr><td>SciPy</td><td>1.10.1</td></tr><tr><td>matplotlib</td><td>3.7.1</td></tr><tr><td>cupy</td><td>None</td></tr><tr><td>numba</td><td>0.57.1</td></tr><tr><td>IPython</td><td>8.14.0</td></tr><tr><td>Python</td><td>3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Tue Jan 30 14:03:06 2024 PST</td></tr></table>"
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>tdgl</td><td>0.8.1; git revision 25e009d [2024-04-10]</td></tr><tr><td>Numpy</td><td>1.24.3</td></tr><tr><td>SciPy</td><td>1.10.1</td></tr><tr><td>matplotlib</td><td>3.7.1</td></tr><tr><td>cupy</td><td>None</td></tr><tr><td>numba</td><td>0.57.1</td></tr><tr><td>IPython</td><td>8.14.0</td></tr><tr><td>Python</td><td>3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Wed Apr 10 14:29:46 2024 PDT</td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/mesh.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Constructing Voronoi polygons: 100%|███████| 525/525 [00:00<00:00, 21148.77it/s]\n"
"Constructing Voronoi polygons: 100%|█████████████████████████████████████████████████████████████████████| 525/525 [00:00<00:00, 20974.72it/s]\n"
]
}
],
Expand Down
8 changes: 4 additions & 4 deletions docs/notebooks/polygons.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Constructing Voronoi polygons: 100%|███████| 459/459 [00:00<00:00, 16564.44it/s]\n",
"Constructing Voronoi polygons: 100%|███████| 459/459 [00:00<00:00, 16243.28it/s]\n",
"Constructing Voronoi polygons: 100%|███████| 459/459 [00:00<00:00, 17103.94it/s]\n"
"Constructing Voronoi polygons: 100%|█████████████████████████████████████████████████████████████████████| 459/459 [00:00<00:00, 17015.81it/s]\n",
"Constructing Voronoi polygons: 100%|█████████████████████████████████████████████████████████████████████| 459/459 [00:00<00:00, 17668.90it/s]\n",
"Constructing Voronoi polygons: 100%|█████████████████████████████████████████████████████████████████████| 459/459 [00:00<00:00, 17594.46it/s]\n"
]
},
{
Expand Down Expand Up @@ -520,7 +520,7 @@
{
"data": {
"text/html": [
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>tdgl</td><td>0.8.1; git revision 268e366 [2024-01-30]</td></tr><tr><td>Numpy</td><td>1.24.3</td></tr><tr><td>SciPy</td><td>1.10.1</td></tr><tr><td>matplotlib</td><td>3.7.1</td></tr><tr><td>cupy</td><td>None</td></tr><tr><td>numba</td><td>0.57.1</td></tr><tr><td>IPython</td><td>8.14.0</td></tr><tr><td>Python</td><td>3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Tue Jan 30 13:57:41 2024 PST</td></tr></table>"
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>tdgl</td><td>0.8.1; git revision 25e009d [2024-04-10]</td></tr><tr><td>Numpy</td><td>1.24.3</td></tr><tr><td>SciPy</td><td>1.10.1</td></tr><tr><td>matplotlib</td><td>3.7.1</td></tr><tr><td>cupy</td><td>None</td></tr><tr><td>numba</td><td>0.57.1</td></tr><tr><td>IPython</td><td>8.14.0</td></tr><tr><td>Python</td><td>3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Wed Apr 10 14:14:21 2024 PDT</td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
Expand Down
4 changes: 2 additions & 2 deletions docs/notebooks/py-mesh.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Constructing Voronoi polygons: 100%|█████| 4185/4185 [00:00<00:00, 21925.67it/s]\n"
"Constructing Voronoi polygons: 100%|███████████████████████████████████████████████████████████████████| 4185/4185 [00:00<00:00, 22564.43it/s]\n"
]
},
{
Expand Down Expand Up @@ -364,7 +364,7 @@
{
"data": {
"text/html": [
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>tdgl</td><td>0.8.1; git revision 268e366 [2024-01-30]</td></tr><tr><td>Numpy</td><td>1.24.3</td></tr><tr><td>SciPy</td><td>1.10.1</td></tr><tr><td>matplotlib</td><td>3.7.1</td></tr><tr><td>cupy</td><td>None</td></tr><tr><td>numba</td><td>0.57.1</td></tr><tr><td>IPython</td><td>8.14.0</td></tr><tr><td>Python</td><td>3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Tue Jan 30 13:57:24 2024 PST</td></tr></table>"
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>tdgl</td><td>0.8.1; git revision 25e009d [2024-04-10]</td></tr><tr><td>Numpy</td><td>1.24.3</td></tr><tr><td>SciPy</td><td>1.10.1</td></tr><tr><td>matplotlib</td><td>3.7.1</td></tr><tr><td>cupy</td><td>None</td></tr><tr><td>numba</td><td>0.57.1</td></tr><tr><td>IPython</td><td>8.14.0</td></tr><tr><td>Python</td><td>3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Wed Apr 10 14:14:07 2024 PDT</td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
Expand Down
12 changes: 6 additions & 6 deletions docs/notebooks/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Constructing Voronoi polygons: 100%|█████| 4679/4679 [00:00<00:00, 22554.63it/s]\n"
"Constructing Voronoi polygons: 100%|███████████████████████████████████████████████████████████████████| 4679/4679 [00:00<00:00, 21549.80it/s]\n"
]
}
],
Expand Down Expand Up @@ -368,8 +368,8 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Thermalizing: 100%|████████████████████████▉| 100/100 [00:10<00:00, 9.83tau/s ]\n",
"Simulating: 100%|██████████████████████████▉| 150/150 [00:25<00:00, 5.80tau/s ]\n"
"Thermalizing: 100%|██████████████████████████████████████████████████████████████████████████████████████▉| 100/100 [00:10<00:00, 9.48tau/s ]\n",
"Simulating: 100%|████████████████████████████████████████████████████████████████████████████████████████▉| 150/150 [00:27<00:00, 5.38tau/s ]\n"
]
}
],
Expand Down Expand Up @@ -7746,7 +7746,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Simulating: 100%|██████████████████████████▉| 200/200 [00:53<00:00, 3.74tau/s ]\n"
"Simulating: 100%|████████████████████████████████████████████████████████████████████████████████████████▉| 200/200 [04:49<00:00, 1.45s/tau ]\n"
]
}
],
Expand Down Expand Up @@ -12414,7 +12414,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Simulating: 100%|██████████████████████████▉| 200/200 [00:41<00:00, 4.82tau/s ]\n"
"Simulating: 100%|████████████████████████████████████████████████████████████████████████████████████████▉| 200/200 [00:42<00:00, 4.73tau/s ]\n"
]
}
],
Expand Down Expand Up @@ -27214,7 +27214,7 @@
{
"data": {
"text/html": [
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>tdgl</td><td>0.8.1; git revision 268e366 [2024-01-30]</td></tr><tr><td>Numpy</td><td>1.24.3</td></tr><tr><td>SciPy</td><td>1.10.1</td></tr><tr><td>matplotlib</td><td>3.7.1</td></tr><tr><td>cupy</td><td>None</td></tr><tr><td>numba</td><td>0.57.1</td></tr><tr><td>IPython</td><td>8.14.0</td></tr><tr><td>Python</td><td>3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Tue Jan 30 14:29:41 2024 PST</td></tr></table>"
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>tdgl</td><td>0.8.1; git revision 25e009d [2024-04-10]</td></tr><tr><td>Numpy</td><td>1.24.3</td></tr><tr><td>SciPy</td><td>1.10.1</td></tr><tr><td>matplotlib</td><td>3.7.1</td></tr><tr><td>cupy</td><td>None</td></tr><tr><td>numba</td><td>0.57.1</td></tr><tr><td>IPython</td><td>8.14.0</td></tr><tr><td>Python</td><td>3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Wed Apr 10 13:30:36 2024 PDT</td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
Expand Down
15 changes: 11 additions & 4 deletions docs/notebooks/screening.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Constructing Voronoi polygons: 100%|█████| 2862/2862 [00:00<00:00, 22203.78it/s]\n"
"Constructing Voronoi polygons: 100%|███████████████████████████████████████████████████████████████████| 2862/2862 [00:00<00:00, 22832.46it/s]\n"
]
}
],
Expand Down Expand Up @@ -227,7 +227,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Simulating: 100%|██████████████████████████████| 5/5 [00:00<00:00, 10.88tau/s ]\n"
"Simulating: 100%|████████████████████████████████████████████████████████████████████████████████████████████▊| 5/5 [00:00<00:00, 10.05tau/s ]\n"
]
}
],
Expand Down Expand Up @@ -272,6 +272,13 @@
"Maximum sheet current density: 449.9 µA/µm\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
Expand Down Expand Up @@ -334,7 +341,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Simulating: 100%|██████████████████████████████▉| 5/5 [00:55<00:00, 11.16s/tau ]\n"
"Simulating: 100%|████████████████████████████████████████████████████████████████████████████████████████████▉| 5/5 [00:55<00:00, 11.17s/tau ]\n"
]
}
],
Expand Down Expand Up @@ -420,7 +427,7 @@
{
"data": {
"text/html": [
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>tdgl</td><td>0.8.1; git revision 268e366 [2024-01-30]</td></tr><tr><td>Numpy</td><td>1.24.3</td></tr><tr><td>SciPy</td><td>1.10.1</td></tr><tr><td>matplotlib</td><td>3.7.1</td></tr><tr><td>cupy</td><td>None</td></tr><tr><td>numba</td><td>0.57.1</td></tr><tr><td>IPython</td><td>8.14.0</td></tr><tr><td>Python</td><td>3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Tue Jan 30 14:11:39 2024 PST</td></tr></table>"
"<table><tr><th>Software</th><th>Version</th></tr><tr><td>tdgl</td><td>0.8.1; git revision 25e009d [2024-04-10]</td></tr><tr><td>Numpy</td><td>1.24.3</td></tr><tr><td>SciPy</td><td>1.10.1</td></tr><tr><td>matplotlib</td><td>3.7.1</td></tr><tr><td>cupy</td><td>None</td></tr><tr><td>numba</td><td>0.57.1</td></tr><tr><td>IPython</td><td>8.14.0</td></tr><tr><td>Python</td><td>3.10.11 | packaged by conda-forge | (main, May 10 2023, 19:01:19) [Clang 14.0.6 ]</td></tr><tr><td>OS</td><td>posix [darwin]</td></tr><tr><td>Number of CPUs</td><td>Physical: 10, Logical: 10</td></tr><tr><td>BLAS Info</td><td>OPENBLAS</td></tr><tr><td colspan='2'>Wed Apr 10 14:05:16 2024 PDT</td></tr></table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
Expand Down
9 changes: 5 additions & 4 deletions tdgl/device/device.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import numbers
import os
import time
from contextlib import contextmanager, nullcontext
Expand Down Expand Up @@ -88,7 +89,7 @@ def __init__(

for polygon in [self.film] + self.holes:
if not polygon.is_valid:
raise ValueError("Invalid Polygon: {polygon!r}.")
raise ValueError(f"Invalid Polygon: {polygon!r}.")

if len(self.holes) != len(set(hole.name for hole in self.holes)):
raise ValueError("All holes must have a unique name.")
Expand Down Expand Up @@ -416,7 +417,7 @@ def scale(
if not (
isinstance(origin, tuple)
and len(origin) == 2
and all(isinstance(val, (int, float)) for val in origin)
and all(isinstance(val, numbers.Real) for val in origin)
):
raise TypeError("Origin must be a tuple of floats (x, y).")
self._warn_if_mesh_exist("scale()")
Expand Down Expand Up @@ -447,7 +448,7 @@ def rotate(self, degrees: float, origin: Tuple[float, float] = (0, 0)) -> "Devic
if not (
isinstance(origin, tuple)
and len(origin) == 2
and all(isinstance(val, (int, float)) for val in origin)
and all(isinstance(val, numbers.Real) for val in origin)
):
raise TypeError("Origin must be a tuple of floats (x, y).")
self._warn_if_mesh_exist("rotate()")
Expand Down Expand Up @@ -582,7 +583,7 @@ def _create_dimensionless_mesh(
create_submesh=True,
)

def mesh_stats_dict(self) -> Dict[str, Union[int, float, str]]:
def mesh_stats_dict(self) -> Dict[str, Union[numbers.Real, str]]:
"""Returns a dictionary of information about the mesh."""
edge_lengths = self.edge_lengths
areas = self.areas
Expand Down
Loading

0 comments on commit db30117

Please sign in to comment.