libAtoms / workflow

python workflow toolkit
GNU General Public License v2.0
24 stars 17 forks source link

Error in MD run (related to rng?) #289

Closed jungsdao closed 5 months ago

jungsdao commented 5 months ago

After updating to latest version of wfl, I'm having following error when trying to run MD simulation. Do I need to provide rng variable with something? I have tried np.random.Generator as argument of rng, but it still fails. I think it should be documented for users.

multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/site-packages/wfl/autoparallelize/pool.py", line 70, in _wrapped_autopara_wrappable
    outputs = op(*u_args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/site-packages/wfl/generate/md/__init__.py", line 145, in _sample_autopara_wrappable
    assert rng is not None
           ^^^^^^^^^^^^^^^
AssertionError
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/work/home/hjung/Calculation/4_Free_energy_calculation/1_Rh/2_CHO_foundation/finetune_foundation.py", line 785, in <module>
    main(ecutwfc = ecutwfc, cv_range = args.cv_range, verbose=True)
  File "/work/home/hjung/Calculation/4_Free_energy_calculation/1_Rh/2_CHO_foundation/finetune_foundation.py", line 624, in main
    run_md(initial_structures, outfiles, files["mace"], **md_params)
  File "/work/home/hjung/Calculation/4_Free_energy_calculation/1_Rh/2_CHO_foundation/finetune_foundation.py", line 177, in run_md
    sample_md(in_config, out_config, calculator=calculator, 
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/site-packages/wfl/generate/md/__init__.py", line 267, in md
    return autoparallelize(_sample_autopara_wrappable, *args,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/site-packages/wfl/autoparallelize/base.py", line 174, in autoparallelize
    return _autoparallelize_ll(autopara_info, inputs, outputs, func, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/site-packages/wfl/autoparallelize/base.py", line 231, in _autoparallelize_ll
    out = do_in_pool(autopara_info.num_python_subprocesses, autopara_info.num_inputs_per_python_subprocess,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/site-packages/wfl/autoparallelize/pool.py", line 157, in do_in_pool
    for result_group in results:
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/multiprocessing/pool.py", line 873, in next
    raise value
AssertionError
jungsdao commented 5 months ago

When I set rng = np.random I'm getting following error.

Reusing existing output instead of doing wfl.generate.optimize._run_autopara_wrappable since overwrite=False and output is done
Traceback (most recent call last):
  File "/work/home/hjung/Calculation/4_Free_energy_calculation/1_Rh/2_CHO_foundation/finetune_foundation.py", line 785, in <module>
    main(ecutwfc = ecutwfc, cv_range = args.cv_range, verbose=True)
  File "/work/home/hjung/Calculation/4_Free_energy_calculation/1_Rh/2_CHO_foundation/finetune_foundation.py", line 624, in main
    run_md(initial_structures, outfiles, files["mace"], **md_params)
  File "/work/home/hjung/Calculation/4_Free_energy_calculation/1_Rh/2_CHO_foundation/finetune_foundation.py", line 177, in run_md
    sample_md(in_config, out_config, calculator=calculator, 
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/site-packages/wfl/generate/md/__init__.py", line 267, in md
    return autoparallelize(_sample_autopara_wrappable, *args,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/site-packages/wfl/autoparallelize/base.py", line 174, in autoparallelize
    return _autoparallelize_ll(autopara_info, inputs, outputs, func, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hjung/miniforge3/envs/foundation/lib/python3.11/site-packages/wfl/autoparallelize/base.py", line 210, in _autoparallelize_ll
    rng_op = global_rng.spawn(1)[0]
             ^^^^^^^^^^^^^^^^
AttributeError: module 'numpy.random' has no attribute 'spawn'
gelzinyte commented 5 months ago

How about the example from README?

seed=1
rng = np.random.default_rng(seed)
md_configs = md.md(..., rng=rng, ...)
jungsdao commented 5 months ago

How about the example from README?

seed=1
rng = np.random.default_rng(seed)
md_configs = md.md(..., rng=rng, ...)

Thank you, this solved the issue.