-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5308409
commit 9e2326a
Showing
4 changed files
with
145 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,152 @@ | ||
import os | ||
from pprint import pprint | ||
|
||
class API: | ||
|
||
def __init__(self): | ||
#print("init") | ||
self.init = True | ||
|
||
def get_param_suggestions(self): | ||
def load_cache(self): | ||
wgT = [] | ||
activeBentWg = [] | ||
passiveBentWg = [] | ||
neff = [] | ||
|
||
# if input is not a text file, recursively read text files in dir | ||
for root, subdirs, files in os.walk("./Lumerical/cache"): | ||
|
||
for filename in files: | ||
# heat sim files | ||
if filename.startswith("wgT_") and filename.endswith(".mat"): | ||
wgT.append(filename) | ||
_, min_v, max_v, interval_v, _ = filename.split("_") | ||
wgT.append({ | ||
"min_v": float(min_v), | ||
"max_v": float(max_v), | ||
"interval_v": float(interval_v), | ||
"filename": filename, | ||
}) | ||
|
||
elif filename.startswith("neff_") and filename.endswith(".txt"): | ||
neff.append(filename) | ||
_, laser_wavelength, min_v, max_v, interval_v, _ = filename.split("_") | ||
neff.append({ | ||
"laser_wavelength": float(laser_wavelength), | ||
"min_v": float(min_v), | ||
"max_v": float(max_v), | ||
"interval_v": float(interval_v), | ||
"filename": filename, | ||
}) | ||
|
||
elif filename.startswith("activebentwg_") and filename.endswith(".ldf"): | ||
_, start_wavelength, end_wavelength, min_v, max_v, interval_v, _ = filename.split("_") | ||
activeBentWg.append({ | ||
"start_wavelength": float(start_wavelength), | ||
"end_wavelength": float(end_wavelength), | ||
"min_v": float(min_v), | ||
"max_v": float(max_v), | ||
"interval_v": float(interval_v), | ||
"filename": filename, | ||
}) | ||
|
||
|
||
elif filename.startswith("passivebentwg_") and filename.endswith(".ldf"): | ||
_, start_wavelength, end_wavelength, _ = filename.split("_") | ||
passiveBentWg.append({ | ||
"start_wavelength": float(start_wavelength), | ||
"end_wavelength": float(end_wavelength), | ||
"filename": filename, | ||
}) | ||
passiveBentWg.append(filename) | ||
break | ||
|
||
# fallbacks if no files in cache | ||
laser_wavelength = '%.3e' % 1545e-9 | ||
min_v = str(4.5) | ||
max_v = str(4.6) | ||
interval_v = str(0.001) | ||
wavelength_window = '%.2e' % 25e-9 | ||
self.wgT = wgT | ||
self.activeBentWg = activeBentWg | ||
self.passiveBentWg = passiveBentWg | ||
self.neff = neff | ||
|
||
def get_param_suggestions(self): | ||
|
||
# fallbacks if no files in cache | ||
laser_wavelength = 1545e-9 | ||
min_v = 4.5 | ||
max_v = 4.6 | ||
interval_v = 0.001 | ||
wavelength_window = 25e-9 | ||
|
||
if len(neff) > 0: | ||
if len(self.neff) > 0: | ||
# take last file in cache for suggested values | ||
# _, min_v, max_v, interval_v, _ = wgT[-1].split("_") | ||
_, laser_wavelength, min_v, max_v, interval_v, _ = neff[-1].split("_") | ||
last_sim = self.neff[-1] | ||
laser_wavelength = last_sim['laser_wavelength'] | ||
min_v = last_sim['min_v'] | ||
max_v = last_sim['max_v'] | ||
interval_v = last_sim['interval_v'] | ||
|
||
constant_v = min_v if float(min_v) > 0 else str(4.5) | ||
constant_v = min_v if min_v > 0 else 4.5 | ||
|
||
return { | ||
'laser_wavelength': laser_wavelength, | ||
'wavelength_window': wavelength_window, | ||
'min_v': min_v, | ||
'max_v': max_v, | ||
'interval_v': interval_v, | ||
'constant_v': constant_v | ||
'laser_wavelength': '%.3e' % laser_wavelength, | ||
'wavelength_window': '%.2e' % wavelength_window, | ||
'min_v': str(min_v), | ||
'max_v': str(max_v), | ||
'interval_v': str(interval_v), | ||
'constant_v': str(constant_v) | ||
} | ||
|
||
def run(self, params): | ||
print("Running") | ||
# TODO add logic for which to simulate | ||
#look into if wavelength precision changes affect cached sims | ||
#TODO | ||
print("API run func called. Params:") | ||
pprint(params) | ||
# TODO: split each component into own function | ||
# TODO: look into if wavelength precision changes affect cached sims | ||
|
||
# TODO | ||
# heat | ||
cached_to_use = None | ||
for cached in self.wgT: | ||
if (params['max_v'] <= cached['max_v'] and | ||
params['min_v'] >= cached['min_v'] and | ||
params['interval_v'] >= cached['interval_v']): | ||
cached_to_use = cached | ||
break | ||
|
||
if not cached_to_use: | ||
print("Run heat sim") | ||
# run sim | ||
|
||
|
||
# active bend | ||
cached_to_use = None | ||
for cached in self.activeBentWg: | ||
if (params['min_v'] >= cached['min_v'] and | ||
params['max_v'] <= cached['max_v'] and | ||
params['interval_v'] >= cached['interval_v'] and | ||
params['start_wavelength'] >= cached['start_wavelength'] and | ||
params['end_wavelength'] <= cached['end_wavelength']): | ||
cached_to_use = cached | ||
break | ||
|
||
if not cached_to_use: | ||
# run sim | ||
print("run active sim") | ||
|
||
# passive bend | ||
cached_to_use = None | ||
for cached in self.passiveBentWg: | ||
if (params['start_wavelength'] >= cached['start_wavelength'] and | ||
params['end_wavelength'] <= cached['end_wavelength']): | ||
cached_to_use = cached | ||
break | ||
|
||
if not cached_to_use: | ||
# run sim | ||
print("run passive sim") | ||
|
||
# neff | ||
cached_to_use = None | ||
for cached in self.neff: | ||
if (params['min_v'] >= cached['min_v'] and | ||
params['max_v'] <= cached['max_v'] and | ||
params['interval_v'] >= cached['interval_v'] and | ||
params['source_wavelength'] <= cached['laser_wavelength']): | ||
cached_to_use = cached | ||
break | ||
|
||
if not cached_to_use: | ||
# run sim | ||
print("run neff sim") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
from CLI.main import CLI | ||
from API.main import API | ||
|
||
|
||
from pprint import pprint | ||
|
||
|
||
def main(): | ||
Api = API() | ||
Api.load_cache() | ||
defaults = Api.get_param_suggestions() | ||
|
||
Cli = CLI(defaults) | ||
params = Cli.run() | ||
|
||
#pprint(params) | ||
Api.run(params) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |