8. traj_recorder
torchfsm.traj_recorder.IntervalController
¤
A class to control the recording of trajectories at specified intervals.
This class can be used as an input for the control_func
parameters of recorder objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval
|
int
|
The interval at which to record the trajectory. |
1
|
start
|
int
|
The step at which to start recording the trajectory. |
0
|
Source code in torchfsm/traj_recorder.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
__init__
¤
__init__(interval: int = 1, start: int = 0) -> None
Source code in torchfsm/traj_recorder.py
18 19 20 21 22 23 24 |
|
__call__
¤
__call__(step: int) -> bool
Source code in torchfsm/traj_recorder.py
26 27 |
|
torchfsm.traj_recorder._TrajRecorder
¤
A base class for trajectory recorders. A recorder is an object that helps to control the recording of trajectories during a simulation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control_func
|
Optional[Callable[[int], bool]]
|
A function that takes a step as input and returns a boolean indicating whether to record the trajectory at that step. |
None
|
include_initial_state
|
bool
|
If True, the initial state will be included in the trajectory. |
True
|
Source code in torchfsm/traj_recorder.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
control_func
instance-attribute
¤
control_func = lambda step: (
True if step == 0 else control_func(step)
)
trajectory
property
¤
trajectory
Get the recorded trajectory. This method should be implemented by subclasses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
return_in_fourier
|
bool
|
If True, return the trajectory in Fourier space. Default is False. |
required |
Returns:
Type | Description |
---|---|
torch.tensor: The recorded trajectory. |
__init__
¤
__init__(
control_func: Optional[Callable[[int], bool]] = None,
include_initial_state: bool = True,
)
Source code in torchfsm/traj_recorder.py
40 41 42 43 44 45 46 47 48 49 50 51 |
|
set_shutdown_flag
¤
set_shutdown_flag()
Set the shutdown flag to True. This will prevent any further recording of trajectories.
Source code in torchfsm/traj_recorder.py
53 54 55 56 57 58 |
|
record
¤
record(step: int, frame: tensor)
Record the trajectory at a given step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step
|
int
|
The current step. |
required |
frame
|
tensor
|
The current frame to be recorded. |
required |
Source code in torchfsm/traj_recorder.py
60 61 62 63 64 65 66 67 68 69 |
|
torchfsm.traj_recorder.AutoRecorder
¤
Bases: _TrajRecorder
A recorder that save the trajectory at the same devices as the simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control_func
|
Optional[Callable[[int], bool]]
|
A function that takes a step as input and returns a boolean indicating whether to record the trajectory at that step. |
None
|
include_initial_state
|
bool
|
If True, the initial state will be included in the trajectory. |
True
|
Source code in torchfsm/traj_recorder.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
control_func
instance-attribute
¤
control_func = lambda step: (
True if step == 0 else control_func(step)
)
__init__
¤
__init__(
control_func: Optional[Callable[[int], bool]] = None,
include_initial_state: bool = True,
)
Source code in torchfsm/traj_recorder.py
132 133 134 135 136 137 138 |
|
set_shutdown_flag
¤
set_shutdown_flag()
Set the shutdown flag to True. This will prevent any further recording of trajectories.
Source code in torchfsm/traj_recorder.py
53 54 55 56 57 58 |
|
record
¤
record(step: int, frame: tensor)
Record the trajectory at a given step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step
|
int
|
The current step. |
required |
frame
|
tensor
|
The current frame to be recorded. |
required |
Source code in torchfsm/traj_recorder.py
60 61 62 63 64 65 66 67 68 69 |
|
torchfsm.traj_recorder.CPURecorder
¤
Bases: AutoRecorder
A recorder that saves the trajectory on the CPU memory. This is useful for large trajectories that may not fit in GPU memory during simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control_func
|
Optional[Callable[[int], bool]]
|
A function that takes a step as input and returns a boolean indicating whether to record the trajectory at that step. |
None
|
include_initial_state
|
bool
|
If True, the initial state will be included in the trajectory. |
True
|
real_time_ifft
|
bool
|
If True, the trajectory will be transformed to real space in real time (if |
True
|
Source code in torchfsm/traj_recorder.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
control_func
instance-attribute
¤
control_func = lambda step: (
True if step == 0 else control_func(step)
)
__init__
¤
__init__(
control_func: Optional[Callable[[int], bool]] = None,
include_initial_state: bool = True,
real_time_ifft: bool = True,
)
Source code in torchfsm/traj_recorder.py
167 168 169 170 171 172 173 174 |
|
set_shutdown_flag
¤
set_shutdown_flag()
Set the shutdown flag to True. This will prevent any further recording of trajectories.
Source code in torchfsm/traj_recorder.py
53 54 55 56 57 58 |
|
record
¤
record(step: int, frame: tensor)
Record the trajectory at a given step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step
|
int
|
The current step. |
required |
frame
|
tensor
|
The current frame to be recorded. |
required |
Source code in torchfsm/traj_recorder.py
60 61 62 63 64 65 66 67 68 69 |
|
torchfsm.traj_recorder.DiskRecorder
¤
Bases: _TrajRecorder
A recorder that saves the trajectory on the disk. This is useful for large trajectories that may not fit in GPU memory during simulation. The trajectory is saved in a temporary cache and then written to disk at specified intervals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control_func
|
Optional[Callable[[int], bool]]
|
A function that takes a step as input and returns a boolean indicating whether to record the trajectory at that step. |
None
|
include_initial_state
|
bool
|
If True, the initial state will be included in the trajectory. |
True
|
cache_dir
|
Optional[str]
|
The directory where the trajectory will be saved. Default is "./saved_traj/". |
None
|
cache_freq
|
int
|
The frequency at which to save the trajectory to disk. Default is 1. |
1
|
temp_cache_loc
|
Literal['auto', 'cpu']
|
The location of the temporary cache. Default is "cpu". |
'cpu'
|
save_format
|
Literal['numpy', 'torch']
|
The format in which to save the trajectory. Default is "torch". |
'torch'
|
Source code in torchfsm/traj_recorder.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
control_func
instance-attribute
¤
control_func = lambda step: (
True if step == 0 else control_func(step)
)
__init__
¤
__init__(
control_func: Optional[Callable[[int], bool]] = None,
include_initial_state: bool = True,
cache_dir: Optional[str] = None,
cache_freq: int = 1,
temp_cache_loc: Literal["auto", "cpu"] = "cpu",
save_format: Literal["numpy", "torch"] = "torch",
)
Source code in torchfsm/traj_recorder.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
set_shutdown_flag
¤
set_shutdown_flag()
Set the shutdown flag to True. This will prevent any further recording of trajectories.
Source code in torchfsm/traj_recorder.py
53 54 55 56 57 58 |
|
record
¤
record(step: int, frame: tensor)
Record the trajectory at a given step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step
|
int
|
The current step. |
required |
frame
|
tensor
|
The current frame to be recorded. |
required |
Source code in torchfsm/traj_recorder.py
60 61 62 63 64 65 66 67 68 69 |
|