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

Update length scale measurement scripts to use new imageruler #64

Merged
merged 2 commits into from
Apr 10, 2024
Merged
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
53 changes: 53 additions & 0 deletions .github/workflows/measure_length_scales.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
pull_request:
push:
branches:
- main
schedule:
- cron: "0 13 * * 1" # Every Monday at 9AM EST

jobs:
measure-length-scales:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup environment
run: |
python -m pip install --upgrade pip
pip install numpy
pip install imageruler
pip install ceviche-challenges
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, these are dependencies for the length scale scripts. The alternative would be to specify dependencies in a separate file (e.g. with a pyproject.toml), but since this repo is more of a collection of scripts I went for this approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is ceviche-challenges a dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It’s a dependency in the script for the mode converter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(The mode converter script measures length scale and also evaluates the performance of the design.)


- name: cavity_design
run: |
cd cavity_design
python minimum_lengthscales_run.py
stevengj marked this conversation as resolved.
Show resolved Hide resolved
cd ..

- name: Metagrating3D
run: |
cd Metagrating3D
python minimum_lengthscales_run.py
cd ..

- name: RGB_metalens
run: |
cd RGB_metalens
python minimum_lengthscales_run.py
cd ..

- name: slow_light_waveguide
run: |
cd slow_light_waveguide
python minimum_lengthscales_run.py
cd ..

- name: waveguide_mode_converter
run: |
cd waveguide_mode_converter
python run.py designs/converter_generator_circle_6_x47530832_w1_s796.csv
cd ..
17 changes: 10 additions & 7 deletions Metagrating3D/minimum_lengthscales_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
file_name = str(file)
if file_name[-3:] == 'csv':
design_pattern = np.loadtxt(path+file_name, delimiter=',')
design_dimension = np.ndim(design_pattern)
if design_pattern.ndim == 1:
design_pattern = design_pattern[:, np.newaxis]
pixel_size = px / design_pattern.shape[0]

if design_dimension == 2: design_size = (px, py)
elif design_dimension == 1: design_size = px
else: AssertionError("Invalid dimension of the design pattern.")

solid_mls, void_mls = imageruler.minimum_length_solid_void(design_pattern, design_size, periodic_axes=(0,1))
print(file_name, solid_mls, void_mls, min(solid_mls, void_mls))
binary_design_pattern = design_pattern > 0.5
solid_mls_pixels, void_mls_pixels = imageruler.minimum_length_scale(
binary_design_pattern, periodic=(True, True)
)
solid_mls = solid_mls_pixels * pixel_size
void_mls = void_mls_pixels * pixel_size
print(path+file_name, solid_mls, void_mls, min(solid_mls, void_mls))
14 changes: 10 additions & 4 deletions RGB_metalens/minimum_lengthscales_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
if file_name[-3:] == 'csv':
design_pattern = np.genfromtxt(path+file_name, delimiter=',')

if file_name[0].upper() == 'M': design_size = 20*np.array(design_pattern.shape)
elif file_name[0].upper() in ('R', 'W'): design_size = 10*np.array(design_pattern.shape)
else: AssertionError("Unknown file name.")
if file_name[0].upper() == 'M':
pixel_size = 20
elif file_name[0].upper() in ('R', 'W'):
pixel_size = 10
else:
raise AssertionError("Unknown file name.")

solid_mls, void_mls = imageruler.minimum_length_solid_void(design_pattern, design_size)
binary_design_pattern = design_pattern > 0.5
solid_mls_pixels, void_mls_pixels = imageruler.minimum_length_scale(binary_design_pattern)
solid_mls = solid_mls_pixels * pixel_size
void_mls = void_mls_pixels * pixel_size
print(path+file_name, solid_mls, void_mls, min(solid_mls, void_mls))
8 changes: 6 additions & 2 deletions cavity_design/minimum_lengthscales_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import imageruler

print('Design file, solid minimum lengthscale (nm), void minimum lengthscale (nm), minimum lengthscale (nm)')
design_size = (2000, 2000)
pixel_size = 5

for path in ['Mo/', 'Göktuğ/']:
files = os.listdir(path)
Expand All @@ -13,5 +13,9 @@
file_name = str(file)
if file_name[-3:] == 'csv':
design_pattern = np.genfromtxt(path+file_name, delimiter=',')
solid_mls, void_mls = imageruler.minimum_length_solid_void(design_pattern, design_size)

binary_design_pattern = design_pattern > 0.5
solid_mls_pixels, void_mls_pixels = imageruler.minimum_length_scale(binary_design_pattern)
solid_mls = solid_mls_pixels * pixel_size
void_mls = void_mls_pixels * pixel_size
print(path+file_name, solid_mls, void_mls, min(solid_mls, void_mls))
11 changes: 5 additions & 6 deletions slow_light_waveguide/minimum_lengthscales_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
files.sort()
print('Design file, solid minimum lengthscale (a), void minimum lengthscale (a), minimum lengthscale (a)')

design_size = (1, 10.2)

for file_name in ['Design_Dnum_2.csv', 'HigRes_DesMatch_Opt_Dnum_2.csv']:
design_pattern = np.loadtxt(path+file_name, delimiter=',')
design_dimension = np.ndim(design_pattern)
design_permittivity = np.loadtxt(path+file_name, delimiter=',')

solid_mls, void_mls = imageruler.minimum_length_solid_void(design_pattern, design_size, periodic_axes=(0,1))
print(file_name, solid_mls, void_mls, min(solid_mls, void_mls))
midpoint = (np.amax(design_permittivity) + np.amin(design_permittivity)) / 2
binary_design_pattern = design_permittivity > midpoint
solid_mls, void_mls = imageruler.minimum_length_scale(binary_design_pattern, periodic=(True, True))
print(file_name, solid_mls, void_mls, min(solid_mls, void_mls))
13 changes: 8 additions & 5 deletions waveguide_mode_converter/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
INPUT_PORT_IDX = 0
OUTPUT_PORT_IDX = 1

pixel_size = 10

parser = argparse.ArgumentParser()
parser.add_argument(
'file',
Expand Down Expand Up @@ -58,10 +60,11 @@
reflection_dB_worst = np.max(s_params_dB[:, INPUT_PORT_IDX])
transmission_dB_worst = np.min(s_params_dB[:, OUTPUT_PORT_IDX])

length_scale = imageruler.minimum_length(
model.density(design),
tuple(v * params.resolution.to_value(u.nm) for v in model.shape))

binary_design_pattern = model.density(design) > 0.5
solid_mls_pixels, void_mls_pixels = imageruler.minimum_length_scale(binary_design_pattern)
solid_mls = solid_mls_pixels * pixel_size
void_mls = void_mls_pixels * pixel_size
print(
f'{os.path.basename(filepath)}, {length_scale}, {reflection_dB_worst:.2f}, {transmission_dB_worst:.2f}'
f'{os.path.basename(filepath)}, ({solid_mls}, {void_mls}), '
f'{reflection_dB_worst:.2f}, {transmission_dB_worst:.2f}'
)