Skip to content

Commit

Permalink
Add progress bar in DynamicsData.from_solution()
Browse files Browse the repository at this point in the history
  • Loading branch information
loganbvh committed Oct 26, 2023
1 parent 00875f3 commit 0a20b5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion tdgl/solution/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,15 @@ def to_hdf5(self, h5group: h5py.Group) -> None:
def from_solution(
solution_path: str,
probe_points: Optional[Sequence[Tuple[float, float]]] = None,
progress_bar: bool = False,
) -> "DynamicsData":
"""Load :class:`DynamicsData` from the saved time steps of a :class:`tdgl.Solution`.
Args:
solution_path: Path to the :class:`tdgl.Solution`
probe_points: The probe coordinates for which to extract dynamics.
If ``None``, defaults to ``solution.device.probe_points``.
progress_bar: Show a progress bar while loading data.
Returns:
A new :class:`DynamicsData` instance
Expand Down Expand Up @@ -485,7 +487,11 @@ def from_solution(
thetas = np.zeros((num_probes, num_steps))

with h5py.File(solution_path, "r") as h5file:
for i in range(step_min, step_max + 1):
for i in tqdm(
range(step_min, step_max + 1),
desc="Time steps",
disable=(not progress_bar),
):
grp = h5file[f"data/{i}"]
times[i] = float(grp.attrs["time"])
mus[:, i] = np.array(grp["mu"])[probe_point_indices]
Expand Down
4 changes: 2 additions & 2 deletions tdgl/test/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def test_dynamics(solution: tdgl.Solution):
assert len(time) == (solution.data_range[1] + 1)
assert solution.closest_solve_step(0) == 0

_ = DynamicsData.from_solution(solution.path, probe_points=None)
_ = DynamicsData.from_solution(solution.path, probe_points=None, progress_bar=True)
_ = DynamicsData.from_solution(
solution.path, probe_points=solution.device.probe_points
solution.path, probe_points=solution.device.probe_points, progress_bar=False
)


Expand Down

0 comments on commit 0a20b5b

Please sign in to comment.