Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named 'ruamel_yaml' #5

Open
superstar54 opened this issue Jun 25, 2022 · 2 comments
Open

No module named 'ruamel_yaml' #5

superstar54 opened this issue Jun 25, 2022 · 2 comments

Comments

@superstar54
Copy link
Member

superstar54 commented Jun 25, 2022

Describe the bug
@alchem0x2A
I pull the latest batoms_api, and did a simple test. I got an error with module ruamel_yaml.

To Reproduce
Input python script:

from ase.io import read
from batoms_api import render
atoms = read("datas/tio2.cif")

config = {
    "batoms_input": {"label": "test_batoms"},
    "settings": {
        "model_style": 2,
        "render": {"engine": "cycles", "samples": 1, "resolution": [20, 20]},
        "bonds": {
            "show_search": True,
        },
        "polyhedras": {
            "setting": {"Ti": {"color": [0, 0.5, 0.5, 0.5]}}},
    }
}
render(atoms, save_blender_file=True, **config)
(base) xing@thinkpad:~/batoms/api_test$ python test.py 
INFO [batoms_api <module>]: Log file: /tmp/beautiful_atoms_api.log
INFO [batoms_api <module>]: Python version: 3.8.5 (default, Sep  4 2020, 07:30:14) 
[GCC 7.3.0] 
DEBUG [batoms_api.batoms_api render]: Write input file /home/xing/batoms/api/.batoms.inp
Blender 3.0.0 (hash f1cca3055776 built 2021-12-03 00:34:54)
Read prefs: /home/xing/.config/blender/3.0/config/userpref.blend
CAD_Sketcher:{INFO}: Logging into: /tmp/CAD_Sketcher.log
INFO [batoms     set_logger]: Log file: /tmp/beautiful_atoms.log
INFO [batoms     set_logger]: Blender version: 3.0.0 
INFO [batoms     set_logger]: Python version: 3.9.7 (default, Oct 11 2021, 10:06:01) 
[GCC 9.3.1 20200408 (Red Hat 9.3.1-2)] 
INFO [batoms     set_logger]: Beautiful Atoms version: (2, 1, 0) 
INFO [batoms     set_logger]: Beautiful Atoms directory: /home/xing/apps/beautiful-atoms 
INFO [batoms     register  ]: Batoms init time: 1.02
Error: Python: Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/xing/apps/python-package/beautiful-atoms-api/batoms_api/__init__.py", line 9, in <module>
    from .batoms_api import render
  File "/home/xing/apps/python-package/beautiful-atoms-api/batoms_api/batoms_api.py", line 7, in <module>
    from ruamel_yaml import YAML
ModuleNotFoundError: No module named 'ruamel_yaml'

location: <unknown location>:-1

Python: Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/xing/apps/python-package/beautiful-atoms-api/batoms_api/__init__.py", line 9, in <module>
    from .batoms_api import render
  File "/home/xing/apps/python-package/beautiful-atoms-api/batoms_api/batoms_api.py", line 7, in <module>
    from ruamel_yaml import YAML
ModuleNotFoundError: No module named 'ruamel_yaml'

location: <unknown location>:-1

Error: script failed, expr: 'from batoms_api import script_api; script_api.run()', exiting.
Traceback (most recent call last):
  File "test.py", line 17, in <module>
    render(atoms, save_blender_file=True, **config)
  File "/home/xing/apps/python-package/beautiful-atoms-api/batoms_api/batoms_api.py", line 222, in render
    blender_run(input_file, dryrun=dryrun, **options)
  File "/home/xing/apps/python-package/beautiful-atoms-api/batoms_api/batoms_api.py", line 150, in blender_run
    raise RuntimeError(
RuntimeError: Running following rendering script
['blender', '-b', '--python-exit-code', '1', '--python-expr', 'from batoms_api import script_api; script_api.run()', '--', '/home/xing/batoms/api/.batoms.inp']
fails with return code 1.

Reason

The command inside blender_run is

['blender', '-b', '--python-exit-code', '1', '--python-expr', 'from batoms_api import script_api; script_api.run()', '--', '/home/xing/batoms/api/.batoms.inp']

In this case, when running blender, the command will import batoms_api inside the Blender's Python. However, we only install batoms_api and its dependencies on the local Python environment.

We need to avoid importing batoms_api inside Blender. Maybe to use the old method:

#
    blender_cmd = 'blender'
    root = os.path.normpath(os.path.dirname(__file__))
    script = os.path.join(root, 'script-api.py')
    if display:
        cmd = blender_cmd + ' -P ' + script
    elif queue == 'SLURM':
        cmd = 'srun -n $SLURM_NTASKS ' +  blender_cmd + ' -b ' + ' -P ' + script
    else:
        cmd = blender_cmd + ' -b ' + ' -P ' + script
    errcode = os.system(cmd)
@alchem0x2A
Copy link
Collaborator

That's a good point. If installing batoms_api using pip associated with blender's python ($BLENDERPY -m pip install -e . or directly following the conda installation using install.py) the import issue should be solved (ruamel_yaml is a dependency of pymatgen), I should state that in the doc.

But your points are valid, to minimize the hassles, we should try to separate batoms and api as much as possible. My current design for batoms_api looks like follows:

  1. Host side: batoms_api checks values from user imput, merge with default dict and dump to .inp file (with metadata like api version etc)
  2. Render side: batoms_api.script_api loads the pickle file, checks with its version and apply settings to batoms object according to the schema dict.

The main reason I chose to not render using $BLENDER -b -P <path/to/script_api.py> is because in some cases path on the render side can be different from the host side (say, render in a container image, or there are multiple copies of batoms_api), but importing batoms_api will ensure the version and file path are all compatible.

If installing via pip solves this issue we can leave it as is. But I do have a feeling that all the rendering parts should be intergrated into batoms itself in the end, so that we don't need to bother the importing or file path issues

@alchem0x2A
Copy link
Collaborator

A possible solution is proposed in #7. Can implement after finishing compatibility with batoms v2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants