diffsims icon indicating copy to clipboard operation
diffsims copied to clipboard

Add simple progress bar to simulations

Open viljarjf opened this issue 11 months ago • 4 comments

Description of the change

Adds a simple progress bar for simulations with SimulationGenerator

Progress of the PR

Minimal example of the bug fix or new feature

from orix.quaternion import Rotation
from orix.crystal_map import Phase
from diffsims.generators.simulation_generator import SimulationGenerator
from diffpy.structure import Atom, Lattice, Structure

# Each phase gets its own progress bar
l = Lattice(1, 2, 3, 90, 100, 110)
atoms = [Atom("C", (0, 0, 0))]
s = Structure(atoms, l)
p1 = Phase("first phase", space_group=1, structure=s)
p2 = Phase("number 2", space_group=191, structure=s)

rots1 = Rotation.random(1000)
rots2 = Rotation.random(2000)

gen = SimulationGenerator()
sims = gen.calculate_diffraction2d(
    phase=[p1, p2],
    rotation=[rots1, rots2],
    show_progressbar=True,
)

>>> first phase: 100%|██████████| 1000/1000 [00:00<00:00, 2725.90it/s]
>>> number 2: 100%|██████████| 2000/2000 [00:01<00:00, 1909.23it/s]

For reviewers

  • [x] The PR title is short, concise, and will make sense 1 year later.
  • [x] New functions are imported in corresponding __init__.py.
  • [ ] New features, API changes, and deprecations are mentioned in the unreleased section in CHANGELOG.rst.
  • [ ] Contributor(s) are listed correctly in credits in diffsims/release_info.py and in .zenodo.json.

viljarjf avatar Jan 14 '25 10:01 viljarjf

@viljarjf I've just realised you aren't on the contributors list. I think you would go in above Isabel Wood. Similarly if you're happy to update the changelog that would be great :)

pc494 avatar Jan 18 '25 15:01 pc494

@pc494 Done! I saw briefly that the two new tests were failing on 3.8, but passed on all other versions. I can't access the logs anymore, but I can see if I can replicate that locally. Is 3.8 still supported?

viljarjf avatar Jan 22 '25 09:01 viljarjf

All tests pass on both windows and ubuntu using 3.8.20 for me. In the test workflow, tqdm is forced to version 4.9 (latest is 4.67) so I tried downgrading, and the tests pass with tqdm>=4.13. Seeing as python 3.6 was officially supported from tqdm 4.11 (i.e. it's getting old), we could consider upgrading tqdm?

viljarjf avatar Jan 22 '25 09:01 viljarjf

I think we should move the minimumPy version to 3.9, test against versions 3.13 and 3.14. For tqdm I suggest picking a sensible looking 4.x patch from early 2024?

pc494 avatar Jan 22 '25 10:01 pc494

Merging for now. (and hopefully this won't break things :))

CSSFrancis avatar May 30 '25 14:05 CSSFrancis