SurfaceSequence¶
- class dnois.optics.rt.SurfaceSequence(surfaces: Sequence[Surface] = None, foremost_material: Material | str = 'vacuum', stop_idx: int = None)¶
A sequential container of surfaces. This class is derived from
torch.nn.ModuleList
and implementscollections.abc.MutableSequence
interface. So its instance can be regarded as both a PyTorch module and a list ofSurface
.- Parameters:
- extra_repr() str ¶
Return the extra representation of the module.
To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.
- forward(ray: BatchedRay, forward: bool = True) BatchedRay ¶
Traces rays incident on the first surface and returns rays passing the last surface, or reversely if
forward
isFalse
.- Parameters:
ray (BatchedRay) – Input rays.
forward (bool) – Whether rays are forward or not.
- Returns:
Output rays.
- Return type:
- freeze(name: str | Sequence[str] = None)¶
Equivalent to
self.set_optimizable(name, False)
. Seeset_optimizable()
.
- classmethod from_dict(d: dict)¶
Constructs an instance of
cls
from adict
.- Parameters:
d (dict) – A
dict
typically returned byto_dict()
.- Returns:
An instance of
cls
.
- classmethod load_json(file, **kwargs) Self ¶
Constructs an instance of
cls
through loading JSON from a file, converting it to adict
and then callingfrom_dict()
.- Parameters:
file (str or
pathlib.Path
or file-like object) – The JSON file to load. Either its path (str
orpathlib.Path
) or a file-like object.kwargs – Keyword arguments passed to
json.load()
.
- Returns:
An instance of
cls
.
- paraxialize(wl: Real | Tensor) ParaxialSystem ¶
Apply
paraxialize()
to this surface sequence.
- save_json(file, **kwargs)¶
Save
self
into a JSON filefile
.- Parameters:
file – The JSON file to save. Either its path (
str
orpathlib.Path
) or a file-like object.kwargs – Keyword arguments passed to
json.dump()
.
- set_optimizable(name: str | Sequence[str] = None, optimizable: bool = True)¶
Specify whether a parameter is optimizable.
- Parameters:
name (str) – Name of the parameter. If
None
, all parameters will be set. It follows the same convention astorch.nn.Module.get_parameter()
.optimizable (bool) – Whether the specified parameter is optimizable. Default:
True
.
- to_dict(keep_tensor=True) dict[str, Any] ¶
Converts
self
into adict
which recursively contains only primitive Python objects.- Return type:
dict
- to_json(**kwargs) str ¶
Converts
self
into a JSON string.- Parameters:
kwargs – Keyword arguments passed to
json.dumps()
.- Return type:
str
- unfreeze(name: str | Sequence[str] = None)¶
Equivalent to
self.set_optimizable(name, True)
. Seeset_optimizable()
.
- property is_empty: bool¶
Whether this list is empty.
- Type:
bool
- mt_head: mt.Material¶
Material before the first surface.
- property stop: CircularStop | None¶
The aperture stop object. Returns
None
if no stop is found. Note that it need not return an instance ofCircularStop
.- Type:
CircularStop
orNone
- property stop_idx: int | None¶
Index of the aperture stop. Returns
None
if no stop is found.- Type:
int or
None