started big cleanup
This commit is contained in:
@@ -1 +0,0 @@
|
||||
include src/scgenerator/data/*
|
||||
@@ -1,3 +1,5 @@
|
||||
# THIS README IS NOT UP TO DATE
|
||||
|
||||
It is recommended to import scgenerator in the following manner :
|
||||
`import scgenerator as sc`
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
\documentclass[preview]{standalone}
|
||||
\usepackage{siunitx}
|
||||
\usepackage{tikz}
|
||||
\usepackage[siunitx]{circuitikz}
|
||||
\usepackage{babel}
|
||||
\usepackage{acronym}
|
||||
\newcommand{\At}{A(z, t)}
|
||||
\newcommand{\Et}{E(z, t)}
|
||||
\newcommand{\Ew}{\tilde{E}(z, \omega)}
|
||||
\newcommand{\PNL}{\tilde{\mathrm{P}}^\mathrm{NL}}
|
||||
|
||||
\begin{document}
|
||||
Complex envelope such that $|A|^2$ is in W with E in V/m~:
|
||||
\begin{equation}
|
||||
\At = \sqrt{\frac12 \epsilon_0 c n A_\mathrm{eff}} \Et
|
||||
\end{equation}
|
||||
|
||||
Equations with E in V/m
|
||||
\begin{equation}
|
||||
\frac{\partial \Ew}{\partial z} = i\left(\beta(\omega) - \frac{\omega}{\nu} \right)\Ew + i \frac{\omega^2}{2c\epsilon_0 \beta(\omega)}\PNL(z, \omega)
|
||||
\end{equation}
|
||||
|
||||
\begin{equation}
|
||||
\tau = t - \frac{z}{\nu}
|
||||
\,, \quad \xi = z
|
||||
\,, \quad \frac{\partial}{\partial z} = -\frac1{\nu}\frac{\partial}{\partial \tau} + \frac{\partial}{\partial \xi} = -\frac{i \omega}{\nu} + \frac{\partial}{\partial \xi}
|
||||
\,, \quad \frac{\partial}{\partial t} = \frac{\partial}{\partial \tau}
|
||||
\end{equation}
|
||||
$\Rightarrow$
|
||||
\begin{equation}
|
||||
\frac{\partial \Ew}{\partial z} = i\beta(\omega)\Ew + i \frac{\omega^2}{2c\epsilon_0 \beta(\omega)}\PNL(z, \omega)
|
||||
\end{equation}
|
||||
|
||||
\end{document}
|
||||
26
pyproject.toml
Normal file
26
pyproject.toml
Normal file
@@ -0,0 +1,26 @@
|
||||
[build-system]
|
||||
requires = ["setuptools"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "scgenerator"
|
||||
version = "0.3.0"
|
||||
description = "Simulate nonlinear pulse propagation in optical fibers"
|
||||
readme = "README.md"
|
||||
authors = [{ name = "Benoit Sierro", email = "benoit.sierro@iap.unibe.ch" }]
|
||||
license = "MIT"
|
||||
classifiers = [
|
||||
"License :: OSI Approved :: MIT",
|
||||
"Programming Language :: Python :: 3",
|
||||
]
|
||||
requires-python = ">=3.10"
|
||||
keywords = ["nonlinear", "fiber optics", "simulation", "runge-kutta"]
|
||||
dependencies = ["numpy >= 1.23", "tomli", "numba", "pydantic", "tqdm"]
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 100
|
||||
[tool.ruff.pydocstyle]
|
||||
convention = "numpy"
|
||||
|
||||
[tool.black]
|
||||
line-length = 100
|
||||
@@ -1,6 +0,0 @@
|
||||
numpy
|
||||
matplotlib
|
||||
scipy
|
||||
tomli
|
||||
tomli-w
|
||||
tqdm
|
||||
42
setup.cfg
42
setup.cfg
@@ -1,42 +0,0 @@
|
||||
[metadata]
|
||||
name = scgenerator
|
||||
version = 0.2.8dev
|
||||
description = Simulated PCFs and supercontinuum generation !
|
||||
author = Benoit Sierro
|
||||
author_email = benoit.sierro@iap.unibe.ch
|
||||
long_description = file: README.md
|
||||
long_description_content_type = text/markdown
|
||||
keywords = supercontinuum, nonlinear optics, GNLSE
|
||||
license = MIT
|
||||
classifiers =
|
||||
License :: OSI Approved :: MIT
|
||||
Programming Language :: Python :: 3
|
||||
|
||||
[options]
|
||||
zip_safe = False
|
||||
include_package_data = True
|
||||
packages = find:
|
||||
package_dir =
|
||||
= src
|
||||
install_requires =
|
||||
numpy
|
||||
numba
|
||||
matplotlib
|
||||
scipy
|
||||
tomli
|
||||
tomli-w
|
||||
tqdm
|
||||
|
||||
|
||||
[options.package_data]
|
||||
scgenerator =
|
||||
data/hr_t.npz
|
||||
data/materials.toml
|
||||
|
||||
[options.packages.find]
|
||||
where = src
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
scgenerator = scgenerator.cli.cli:main
|
||||
sc-submit = scgenerator.scripts.slurm_submit:main
|
||||
7
setup.py
7
setup.py
@@ -1,3 +1,6 @@
|
||||
from setuptools import setup
|
||||
#!/usr/bin/env python
|
||||
|
||||
setup()
|
||||
import setuptools
|
||||
|
||||
if __name__ == "__main__":
|
||||
setuptools.setup()
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
from .cli import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,248 +0,0 @@
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
from collections import ChainMap
|
||||
from pathlib import Path
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
from .. import const, env, scripts, utils
|
||||
from ..logger import get_logger
|
||||
from ..physics.fiber import dispersion_coefficients
|
||||
from ..physics.simulate import SequencialSimulations, run_simulation
|
||||
|
||||
try:
|
||||
import ray
|
||||
except ImportError:
|
||||
ray = None
|
||||
|
||||
|
||||
def set_env_variables(cmd_line_args: dict[str, str]):
|
||||
cm = ChainMap(cmd_line_args, os.environ)
|
||||
for env_key in env.global_config:
|
||||
k = env_key.replace(env.ENVIRON_KEY_BASE, "").lower()
|
||||
v = cm.get(k)
|
||||
if v is not None:
|
||||
os.environ[env_key] = str(v)
|
||||
|
||||
|
||||
def create_parser():
|
||||
parser = argparse.ArgumentParser(description="scgenerator command", prog="scgenerator")
|
||||
subparsers = parser.add_subparsers(help="sub-command help")
|
||||
|
||||
for key, args in env.global_config.items():
|
||||
names = ["--" + key.replace(env.ENVIRON_KEY_BASE, "").replace("_", "-").lower()]
|
||||
if "short_name" in args:
|
||||
names.append(args["short_name"])
|
||||
parser.add_argument(
|
||||
*names, **{k: v for k, v in args.items() if k not in {"short_name", "type"}}
|
||||
)
|
||||
parser.add_argument("--version", action="version", version=const.__version__)
|
||||
|
||||
run_parser = subparsers.add_parser("run", help="run a simulation from a config file")
|
||||
run_parser.add_argument("config", help="path(s) to the toml configuration file(s)")
|
||||
run_parser.set_defaults(func=run_sim)
|
||||
|
||||
merge_parser = subparsers.add_parser("merge", help="merge simulation results")
|
||||
merge_parser.add_argument(
|
||||
"path", help="path to the final simulation folder containing 'initial_config.toml'"
|
||||
)
|
||||
merge_parser.set_defaults(func=merge)
|
||||
|
||||
plot_parser = subparsers.add_parser("plot", help="generate basic plots of a simulation")
|
||||
plot_parser.add_argument(
|
||||
"sim_dir",
|
||||
help="path to the root directory of the simulation (i.e. the "
|
||||
"directory directly containing 'initial_config0.toml'",
|
||||
)
|
||||
plot_parser.add_argument(
|
||||
"spectrum_limits",
|
||||
nargs=argparse.REMAINDER,
|
||||
help="comma-separated list of left limit, right limit and unit. "
|
||||
"One plot is made for each limit set provided. Example : 600,1200,nm or -2,2,ps",
|
||||
)
|
||||
plot_parser.add_argument("--options", "-o", default=None)
|
||||
plot_parser.add_argument(
|
||||
"--show", action="store_true", help="show the plots instead of saving them"
|
||||
)
|
||||
plot_parser.set_defaults(func=plot_all)
|
||||
|
||||
dispersion_parser = subparsers.add_parser(
|
||||
"dispersion", help="show the dispersion of the given config"
|
||||
)
|
||||
dispersion_parser.add_argument("config", help="path to the config file")
|
||||
dispersion_parser.add_argument(
|
||||
"--limits", "-l", default=None, type=float, nargs=2, help="left and right limits in nm"
|
||||
)
|
||||
dispersion_parser.set_defaults(func=plot_dispersion)
|
||||
|
||||
init_pulse_plot_parser = subparsers.add_parser(
|
||||
"plot-spec-field", help="plot the initial field and spectrum"
|
||||
)
|
||||
init_pulse_plot_parser.add_argument("config", help="path to the config file")
|
||||
init_pulse_plot_parser.add_argument(
|
||||
"--wavelength-limits",
|
||||
"-l",
|
||||
default=None,
|
||||
type=float,
|
||||
nargs=2,
|
||||
help="left and right limits in nm",
|
||||
)
|
||||
init_pulse_plot_parser.add_argument(
|
||||
"--time-limit", "-t", default=None, type=float, help="time axis limit in fs"
|
||||
)
|
||||
init_pulse_plot_parser.set_defaults(func=plot_init_field_spec)
|
||||
|
||||
init_plot_parser = subparsers.add_parser("plot-init", help="plot initial values")
|
||||
init_plot_parser.add_argument("config", help="path to the config file")
|
||||
init_plot_parser.add_argument(
|
||||
"--dispersion-limits",
|
||||
"-d",
|
||||
default=None,
|
||||
type=float,
|
||||
nargs=2,
|
||||
help="left and right limits for dispersion plots in nm",
|
||||
)
|
||||
init_plot_parser.add_argument(
|
||||
"--time-limit", "-t", default=None, type=float, help="time axis limit in fs"
|
||||
)
|
||||
init_plot_parser.add_argument(
|
||||
"--wavelength-limits",
|
||||
"-l",
|
||||
default=None,
|
||||
nargs=2,
|
||||
type=float,
|
||||
help="wavelength axis limit in nm",
|
||||
)
|
||||
init_plot_parser.set_defaults(func=plot_init)
|
||||
|
||||
preview_parser = subparsers.add_parser("preview", help="preview a currently running simulation")
|
||||
plc_hld = "XX"
|
||||
preview_parser.add_argument(
|
||||
"path", help=f"path to the directory containing {const.SPEC1_FN.format(plc_hld)!r}"
|
||||
)
|
||||
preview_parser.add_argument(
|
||||
"spectrum_limits",
|
||||
nargs=argparse.REMAINDER,
|
||||
help="comma-separated list of left limit, right limit and unit. "
|
||||
"One plot is made for each limit set provided. Example : 600,1200,nm or -2,2,ps",
|
||||
)
|
||||
preview_parser.set_defaults(func=preview)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def main():
|
||||
parser = create_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
set_env_variables({k: v for k, v in vars(args).items() if v is not None})
|
||||
|
||||
args.func(args)
|
||||
|
||||
logger = get_logger(__name__)
|
||||
logger.info(f"dispersion cache : {dispersion_coefficients.cache_info()}")
|
||||
|
||||
|
||||
def run_sim(args):
|
||||
method = prep_ray()
|
||||
run_simulation(args.config, method=method)
|
||||
# if sys.platform == "darwin" and sys.stdout.isatty():
|
||||
# subprocess.run(
|
||||
# [
|
||||
# "osascript",
|
||||
# "-e",
|
||||
# 'tell app "System Events" to display dialog "simulation finished !"',
|
||||
# ],
|
||||
# stdout=subprocess.DEVNULL,
|
||||
# stderr=subprocess.DEVNULL,
|
||||
# )
|
||||
|
||||
|
||||
def merge(args):
|
||||
path_trees = utils.build_path_trees(Path(args.path))
|
||||
|
||||
output = env.output_path()
|
||||
if output is None:
|
||||
output = path_trees[0][-1][0].parent.name + " merged"
|
||||
|
||||
utils.merge(output, path_trees)
|
||||
|
||||
|
||||
def preview(args):
|
||||
for path in utils.simulations_list(args.path):
|
||||
lims = args.spectrum_limits or [None, "-10,10,ps"]
|
||||
for lim in lims:
|
||||
scripts.partial_plot(path, lim)
|
||||
plt.show()
|
||||
plt.close()
|
||||
|
||||
|
||||
def prep_ray():
|
||||
logger = get_logger(__name__)
|
||||
if ray:
|
||||
if env.get(env.START_RAY):
|
||||
init_str = ray.init()
|
||||
elif not env.get(env.NO_RAY):
|
||||
try:
|
||||
init_str = ray.init(
|
||||
address="auto",
|
||||
_redis_password=os.environ.get("redis_password", "caco1234"),
|
||||
)
|
||||
logger.info(init_str)
|
||||
except ConnectionError as e:
|
||||
logger.warning(e)
|
||||
return SequencialSimulations if env.get(env.NO_RAY) else None
|
||||
|
||||
|
||||
def plot_all(args):
|
||||
opts = {}
|
||||
if args.options is not None:
|
||||
opts |= dict([o.split("=")[:2] for o in re.split("[, ]+", args.options)])
|
||||
root = Path(args.sim_dir).resolve()
|
||||
scripts.plot_all(root, args.spectrum_limits, show=args.show, **opts)
|
||||
|
||||
|
||||
def plot_init_field_spec(args):
|
||||
if args.wavelength_limits is None:
|
||||
l = None
|
||||
else:
|
||||
l = list(args.wavelength_limits)
|
||||
|
||||
if args.time_limit is None:
|
||||
t = None
|
||||
else:
|
||||
t = [-args.time_limit, args.time_limit]
|
||||
|
||||
scripts.plot_init_field_spec(args.config, t, l)
|
||||
|
||||
|
||||
def plot_init(args):
|
||||
if args.wavelength_limits is None:
|
||||
l = None
|
||||
else:
|
||||
l = list(args.wavelength_limits)
|
||||
if args.dispersion_limits is None:
|
||||
d = None
|
||||
else:
|
||||
d = list(args.dispersion_limits)
|
||||
|
||||
if args.time_limit is None:
|
||||
t = None
|
||||
else:
|
||||
t = [-args.time_limit, args.time_limit]
|
||||
|
||||
scripts.plot_init(args.config, t, l, d)
|
||||
|
||||
|
||||
def plot_dispersion(args):
|
||||
if args.limits is None:
|
||||
lims = None
|
||||
else:
|
||||
lims = 1e-9 * np.array(args.limits, dtype=float)
|
||||
scripts.plot_dispersion(args.config, lims)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user