Skip to content

Commit

Permalink
Merge pull request #114 from esa/release-0.1.1
Browse files Browse the repository at this point in the history
Release 0.1.1
  • Loading branch information
gomezzz authored Sep 7, 2022
2 parents dd2f23c + 61397b8 commit 8a697e8
Show file tree
Hide file tree
Showing 28 changed files with 163 additions and 446 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ dmypy.json
my_notebooks
.vscode
results
cfg
cfg
notebooks/plots/
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Neural Inverse Design of Nanostructures (NIDN) is a Python project by the Advanc

<p align="center">
<a href="https://github.com/esa/nidn">
<img src="docs/NIDN_Scheme_v2.drawio.drawio.png" alt="Scheme" width="910" height="459">
<img src="docs/source/NIDN_Scheme_v2.drawio.drawio.png" alt="Scheme" width="910" height="459">
</a>
<p align="center">
Neural Inverse Design of Nanostructures with PyTorch
Expand All @@ -63,6 +63,10 @@ This project is based on:

For more details than provided with NIDN on the forward models please refer to their docs. The adaptations of there code are in the folders [nidn/trcwa/](https://github.com/esa/NIDN/tree/main/nidn/trcwa) and [nidn/fdtd/](https://github.com/esa/NIDN/tree/main/nidn/fdtd).

Below you can see results of an exemplary optimization of a three-uniform-layer material to design a 1150nm filter.

![Exemplary optimization of a three-uniform-layer material to design a 1150nm filter. | width=300](/examples/BP-filter-3layer-opt.gif)
![Exemplary optimization of a three-uniform-layer material to design a 1150nm filter. | width=300](/examples/BP-filter-3layer-eps.gif)
<!-- GETTING STARTED -->

## Getting Started
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
SOURCEDIR = source
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
Expand Down
2 changes: 1 addition & 1 deletion docs/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set SOURCEDIR=source
set BUILDDIR=_build

if "%1" == "" goto help
Expand Down
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion docs/conf.py → docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
author = "Pablo Gómez and Håvard Hem Toftevaag"

# The full version, including alpha/beta/rc tags
release = "v0.0.1"
release = "v0.1.1"


# -- General configuration ---------------------------------------------------
Expand Down
File renamed without changes.
File renamed without changes.
Binary file added examples/BP-filter-3layer-eps.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/BP-filter-3layer-opt.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions nidn/plots/plot_eps_per_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
from ..utils.global_constants import NIDN_FONTSIZE, NIDN_PLOT_COLOR_1


def plot_eps_per_point(run_cfg, compare_to_material=None, save_path=None, legend=True):
def plot_eps_per_point(
run_cfg, compare_to_material=None, save_path=None, legend=True, file_id=None
):
"""This function plots the epsilon values of grid points against real materials. Optionally saves it.
Args:
run_cfg (dict): The run configuration.
compare_to_material (str or list): Name(s) of the material to compare with. Available ones are in /materials/data.
save_path (str, optional): Folder to save the plot in. Defaults to None, then the plot will not be saved.
legend (bool, optional): Whether to show layer legend
file_id (str, optional): Whether to add a postfix string
"""
# Create epsilon grid from the model
eps, _ = model_to_eps_grid(run_cfg.model, run_cfg)
Expand Down Expand Up @@ -147,4 +151,8 @@ def plot_eps_per_point(run_cfg, compare_to_material=None, save_path=None, legend
fig.autofmt_xdate()

if save_path is not None:
plt.savefig(save_path + "/eps_per_points.png", dpi=150)
plt.savefig(save_path + "/eps_per_points" + str(file_id) + ".png", dpi=150)
# fig.clf()
# plt.close(fig)
else:
plt.show()
2 changes: 2 additions & 0 deletions nidn/plots/plot_epsilon_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ def plot_epsilon_grid(eps, run_cfg, save_path=None):

if save_path is not None:
plt.savefig(save_path + "/eps_grid.png", dpi=150)
else:
plt.show()
3 changes: 3 additions & 0 deletions nidn/plots/plot_losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ def plot_losses(run_cfg, save_path=None):
plt.legend(["L1", "Loss", "Weighted Average Loss"])
if save_path is not None:
plt.savefig(save_path + "/losses.png", dpi=150)
else:
plt.show()

3 changes: 3 additions & 0 deletions nidn/plots/plot_material_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ def plot_material_grid(

if save_path is not None:
plt.savefig(save_path + "/material_grid.png", dpi=150)
else:
plt.show()

4 changes: 3 additions & 1 deletion nidn/plots/plot_model_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def plot_model_grid(run_cfg, save_path=None):

# Here we calculate the absolute value of the permittivity over all frequencies for each grid point
eps = torch.mean(eps, dim=3)
eps = torch.sqrt(eps.real ** 2 + eps.imag ** 2)
eps = torch.sqrt(eps.real**2 + eps.imag**2)

abs_values = eps.detach().cpu().numpy()

Expand Down Expand Up @@ -63,3 +63,5 @@ def plot_model_grid(run_cfg, save_path=None):

if save_path is not None:
plt.savefig(save_path + "/model_grid.png", dpi=150)
else:
plt.show()
2 changes: 2 additions & 0 deletions nidn/plots/plot_model_grid_per_freq.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ def plot_model_grid_per_freq(run_cfg, freq_idx=[0, 1, 2, 3], save_path=None):

if save_path is not None:
plt.savefig(save_path + "/model_grid_per_freq.png", dpi=150)
else:
plt.show()
6 changes: 5 additions & 1 deletion nidn/plots/plot_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def plot_spectra(
prod_T_spectrum=None,
markers=True,
filename=None,
ylim=[[0.0, 1.0],[0.0, 1.0]],
ylim=[[0.0, 1.0], [0.0, 1.0]],
):
"""Plots the produced RTA spectra together with the target spectra. Optionally saves it.
Expand Down Expand Up @@ -173,3 +173,7 @@ def plot_spectra(
plt.savefig(save_path + "/spectra_comparison.png", dpi=150)
else:
plt.savefig(save_path + "/" + filename + ".png", dpi=300)
# fig.clf()
# plt.close(fig)
else:
plt.show()
6 changes: 4 additions & 2 deletions nidn/plots/plot_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def plot_spectrum(
# max(max(A_spectrum), max(T_spectrum), max(R_spectrum)) + 0.1,
# ]

fig = plt.figure(figsize=(15, 5), dpi=300)
fig = plt.figure(figsize=(12, 4), dpi=150)
fig.patch.set_facecolor("white")

fig = _add_plot(
Expand All @@ -116,7 +116,7 @@ def plot_spectrum(
target_frequencies,
T_spectrum,
ylimits,
(121 if not show_absorption else 132),
(122 if not show_absorption else 132),
"Transmittance",
markers=markers,
)
Expand All @@ -138,3 +138,5 @@ def plot_spectrum(
plt.savefig(save_path + "/spectrum.png", dpi=150)
else:
plt.savefig(save_path + "/" + filename + ".png", dpi=300)
else:
plt.show()
14 changes: 3 additions & 11 deletions notebooks/FDTD_RCWA_TMM_Comparison.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,11 @@
" plt.ylim([-0.1,1.1])\n",
" plt.savefig(f'../results/{material}.png')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "140d2626",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.6 ('NIDN')",
"display_name": "Python 3.9.7 ('nidn')",
"language": "python",
"name": "python3"
},
Expand All @@ -209,11 +201,11 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.9.7"
},
"vscode": {
"interpreter": {
"hash": "f0a9101947082d57fdb1768cbb738b2d65701c74001bd4e9db965265346a5080"
"hash": "1ec5cfae9b828f8ab7e7cdcd8237afffb09b0704a5815a216abf273e6fa91aea"
}
}
},
Expand Down
13 changes: 9 additions & 4 deletions notebooks/Forward_Model_Simulation_with_FDTD.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"# Choose FDTD method, TRCWA other option\n",
"cfg.solver = \"FDTD\"\n",
"# Set number of time steps in FDTD\n",
"cfg.FDTD_niter = 400\n",
"cfg.FDTD_niter = 600\n",
"# Choose pulse type (continuous, hanning or ricker)\n",
"cfg.FDTD_pulse_type = 'continuous'\n",
"# Choose source type (line or point)\n",
Expand Down Expand Up @@ -160,7 +160,7 @@
"#Largest wavelength\n",
"cfg.physical_wavelength_range[1]=15e-7\n",
"# Set number of time steps in FDTD\n",
"cfg.FDTD_niter = 800\n",
"cfg.FDTD_niter = 2400\n",
"# Choose pulse type\n",
"cfg.FDTD_pulse_type = 'continuous'"
]
Expand Down Expand Up @@ -217,7 +217,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.9.7 ('nidn')",
"language": "python",
"name": "python3"
},
Expand All @@ -231,7 +231,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
"version": "3.9.7"
},
"vscode": {
"interpreter": {
"hash": "1ec5cfae9b828f8ab7e7cdcd8237afffb09b0704a5815a216abf273e6fa91aea"
}
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 8a697e8

Please sign in to comment.