Skip to content

Commit

Permalink
Merge pull request #14 from esa/Rescaled-sampling-in-frequency-domain…
Browse files Browse the repository at this point in the history
…-(to-have-less-volatile-eps-vs-freq)

Rescaled sampling in frequency domain (to have less volatile eps vs freq)
  • Loading branch information
htoftevaag authored Aug 24, 2021
2 parents 9054c6a + c46f8d6 commit d3456e1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
12 changes: 7 additions & 5 deletions nidn/training/model/model_to_eps_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ def _eval_model(model, Nx_undersampled, Ny_undersampled, N_layers, target_freque
y = torch.linspace(-1, 1, Ny_undersampled)
z = torch.linspace(-1, 1, N_layers)

# Scales sampling domain of frequencies
freq_scaling = 32.0

# Linearly spaced frequency points
# freq = torch.linspace(-1,1,len(run_cfg.target_frequencies))
# freq = torch.linspace(-freq_scaling, freq_scaling, len(target_frequencies))

# Logspaced frequency points
# Normalize to max val = 1
freq = torch.tensor(target_frequencies / max(target_frequencies))
# Transform to -1 to 1
freq = (freq * 2) - 1
# Transform to -scaling to scaling
freq = (freq * 2 * freq_scaling) - freq_scaling

# Create a meshgrid from the grid ticks
X, Y, Z, FREQ = torch.meshgrid((x, y, z, freq))
Expand Down Expand Up @@ -76,8 +79,7 @@ def _regression_model_to_eps_grid(model, run_cfg: DotMap):

# Initialize the epsilon grid
eps = torch.zeros(
[run_cfg.Nx, run_cfg.Ny, run_cfg.N_layers, run_cfg.N_freq],
dtype=torch.cfloat,
[run_cfg.Nx, run_cfg.Ny, run_cfg.N_layers, run_cfg.N_freq], dtype=torch.cfloat,
)

# Net out is [0,1] thus we transform to desired real and imaginary ranges
Expand Down
8 changes: 1 addition & 7 deletions nidn/trcwa/init_trcwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ def _init_trcwa(eps_grid, target_frequency):

# Initialize TRCWA object
trcwa = TRCWA(
TRCWA_NG,
TRCWA_L1,
TRCWA_L2,
freqcmp,
TRCWA_THETA,
TRCWA_PHI,
verbose=0,
TRCWA_NG, TRCWA_L1, TRCWA_L2, freqcmp, TRCWA_THETA, TRCWA_PHI, verbose=0,
)

# Add vacuum layer at the top
Expand Down
54 changes: 54 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""A setuptools based setup module.
See:
https://packaging.python.org/guides/distributing-packages-using-setuptools/
https://github.com/pypa/sampleproject
"""

# Always prefer setuptools over distutils
from setuptools import setup, find_packages

setup(
name="nidn",
version="0.1.0",
description="A package for inverse material design of nanostructures using neural networks.",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
url="https://github.com/esa/nidn",
author="ESA Advanced Concepts Team",
author_email="pablo.gomez@esa.int",
install_requires=[
"dotmap>=1.3.24",
"loguru>=0.5.3",
"matplotlib>=3.3.3",
"numpy>=1.20.0",
"pandas>=1.3.1",
"scipy>=1.6.0",
"tqdm>=4.56.1",
"torch>=1.9",
],
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Mathematics",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python :: 3.8",
],
packages=[
"nidn",
"nidn.materials",
"nidn.plots",
"nidn.tests",
"nidn.training",
"nidn.training.losses",
"nidn.training.model",
"nidn.training.utils",
"nidn.trcwa",
"nidn.trcwa.utils",
"nidn.utils",
],
python_requires=">=3.8, <4",
project_urls={
"Source": "https://github.com/esa/nidn/",
},
)

0 comments on commit d3456e1

Please sign in to comment.