environment¶
The Environment class contains all the necessary parameters to initialize a network for a simulation.
environment¶
environment
The Environment class contains all the necessary parameters to initialize a network for a simulation.

class
photontorch.environment.environment.
Environment
(dt=1e14, samplerate=100000000000000.0, num_t=100, t0=0.0, t1=1e12, t=array([0.0, 1e14, ..., 9.9e13]), bitrate=None, bitlength=None, wl=1.55e06, f=193400000000000.0, dwl=1e09, df=129100000000000.0, num_wl=1, num_f=1, wl0=1.5e06, f0=187400000000000.0, wl1=1.6e06, f1=199900000000000.0, c=299800000.0, freqdomain=0, grad=0, name='env', **kwargs)¶ Bases:
object
Simulation Environment
The simulation environment is a smart data class that contains all the necessary parameters to initialize a network for a simulation.
It is able to initialize parameters that depend on each other correctly.
Note
After creating an Environment, the parameters of the environment get frozen and cannot be changed. However, a new environment can be created from the old one with the
.copy
method, which accepts the same arguments as Environment, but uses the current values as defaults.
__init__
(dt=1e14, samplerate=100000000000000.0, num_t=100, t0=0.0, t1=1e12, t=array([0.0, 1e14, ..., 9.9e13]), bitrate=None, bitlength=None, wl=1.55e06, f=193400000000000.0, dwl=1e09, df=129100000000000.0, num_wl=1, num_f=1, wl0=1.5e06, f0=187400000000000.0, wl1=1.6e06, f1=199900000000000.0, c=299800000.0, freqdomain=0, grad=0, name='env', **kwargs)¶  Parameters
t (np.ndarray) – [s] full 1D time array (mutually exclusive with dt, t0, t1, num_t and samplerate).
t0 (float) – [s] starting time of the simulation (mutually exclusive with t).
t1 (float) – [s] ending time of the simulation (mutually exclusive with t and num_t).
num_t (int) – number of timesteps in the simulation (mutually exclusive with t, dt and samplerate).
dt (float) – [s] timestep of the simulation (mutually exclusive with t and samplerate)
samplerate (float) – [1/s] samplerate of the simulation (mutually exclusive with t and t1).
bitrate (optional, float) – [1/s] bitrate of the signal (mutually exclusive with bitlength).
bitlength (optional, float) – [s] bitlength of the signal (mutually exclusive with bitrate).
wl (float) – [m] full 1D wavelength array (mutually exclusive with f, dwl, df, num_wl, num_f, wl0, f0, wl1 and f1).
wl0 (float) – [m] start of wavelength range (mutually exclusive with wl, f and f0).
wl1 (float) – [m] end of wavelength range (mutually exclusive with wl, f and f1).
num_wl (int) – number of independent wavelengths in the simulation (mutually exclusive with wl, f, num_f, dwl and df)
dwl (float) – [m] wavelength step sizebetween wl0 and wl1 (mutually exclusive with wl, f, df, num_wl and num_f).
f (float) – [1/s] full 1D frequency array (mutually exclusive with wl, dwl, df, num_wl, num_f, wl0, f0, wl1 and f1).
f0 (float) – [1/s] start of frequency range (mutually exclusive with wl, f and wl0).
f1 (float) – [1/s] end of frequency range (mutually exclusive with wl, f and wl1).
num_f (int) – number of independent frequencies in the simulation (mutually exclusive with wl, f, num_wl, dwl and df)
df (float) – [1/s] frequency step between f0 and f1 (mutually exclusive with wl, f, dwl, num_wl and num_f).
c (float) – [m/s] speed of light used during simulations.
freqdomain (bool) – only do frequency domain calculations.
grad (bool) – track gradients during the simulation (set this to True during training.)
name (str) – name of the environment
**kwargs (optional) – any number of extra keyword arguments will be stored as attributes to the environment.

copy
(**kwargs)¶ Create a copy of the environment
Note
This copy method accepts the same keyword arguments as the Environment initialization. Supplying arguments overrides the values in the copied environment. The original environment remains unchanged.
 Parameters
t (np.ndarray) – [s] full 1D time array (mutually exclusive with dt, t0, t1, num_t and samplerate).
t0 (float) – [s] starting time of the simulation (mutually exclusive with t).
t1 (float) – [s] ending time of the simulation (mutually exclusive with t and num_t).
num_t (int) – number of timesteps in the simulation (mutually exclusive with t, dt and samplerate).
dt (float) – [s] timestep of the simulation (mutually exclusive with t and samplerate)
samplerate (float) – [1/s] samplerate of the simulation (mutually exclusive with t and t1).
bitrate (optional, float) – [1/s] bitrate of the signal (mutually exclusive with bitlength).
bitlength (optional, float) – [s] bitlength of the signal (mutually exclusive with bitrate).
wl (float) – [m] full 1D wavelength array (mutually exclusive with f, dwl, df, num_wl, num_f, wl0, f0, wl1 and f1).
wl0 (float) – [m] start of wavelength range (mutually exclusive with wl, f and f0).
wl1 (float) – [m] end of wavelength range (mutually exclusive with wl, f and f1).
num_wl (int) – number of independent wavelengths in the simulation (mutually exclusive with wl, f, num_f, dwl and df)
dwl (float) – [m] wavelength step sizebetween wl0 and wl1 (mutually exclusive with wl, f, df, num_wl and num_f).
f (float) – [1/s] full 1D frequency array (mutually exclusive with wl, dwl, df, num_wl, num_f, wl0, f0, wl1 and f1).
f0 (float) – [1/s] start of frequency range (mutually exclusive with wl, f and wl0).
f1 (float) – [1/s] end of frequency range (mutually exclusive with wl, f and wl1).
num_f (int) – number of independent frequencies in the simulation (mutually exclusive with wl, f, num_wl, dwl and df)
df (float) – [1/s] frequency step between f0 and f1 (mutually exclusive with wl, f, dwl, num_wl and num_f).
c (float) – [m/s] speed of light used during simulations.
freqdomain (bool) – only do frequency domain calculations.
grad (bool) – track gradients during the simulation (set this to True during training.)
name (str) – name of the environment
**kwargs (optional) – any number of extra keyword arguments will be stored as attributes to the environment.


photontorch.environment.environment.
current_environment
()¶ get the current environment

photontorch.environment.environment.
set_environment
(*args, **kwargs)¶ set the environment globally
 Parameters
env (Environment) – The environment to set globally.
**kwargs – keyword arguments to define a new environment.
Note
It is recommended to set the Environment using a withblock. However, if you would like to set the environment globally, this can be done with this function.