materialsvirtuallab / maml

Python for Materials Machine Learning, Materials Descriptors, Machine Learning Force Fields, Deep Learning, etc.
BSD 3-Clause "New" or "Revised" License
364 stars 79 forks source link

Fix `setup.py` package data so `pip install` without GitHub clone also works for `M3GNetStructure` #638

Closed kavanase closed 3 months ago

kavanase commented 3 months ago

When trying to parse Structure objects with M3GNetStructure, the following error is encountered:

Traceback (most recent call last):
  File "M3GNet_Structure_DIRECT_generation_test_Y.py", line 35, in <module>
    m3gnet_struct = M3GNetStructure()  # neither multiprocessing nor Parallel works for this
  File "/work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/maml/describers/_m3gnet.py", line 35, in __init__
    self.describer_model = M3GNet.from_dir(DEFAULT_MODEL)
  File "/work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/m3gnet/models/_m3gnet.py", line 336, in from_dir
    model.load_weights(model_name)
  File "/work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/tensorflow/python/training/py_checkpoint_reader.py", line 31, in error_translator
    raise errors_impl.NotFoundError(None, None, error_message)
tensorflow.python.framework.errors_impl.NotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for /work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/maml/describers/data/m3gnet_models/matbench_mp_e_form/0/m3gnet/m3gnet

which seems to be because the M3GNet model data from maml/describers/data/m3gnet_models/matbench_mp_e_form/0/m3gnet is not available in the package data – so works fine for GitHub Actions tests run in the cloned repo, but not when actually used elsewhere in scripts/notebooks. Fixing package_data in setup.py fixes this.

Also fixes a typo in setup.py for megnet_models (previously megnet_mdoels).

I would also note that this also fails with recent tensorflow versions (2.16) which uses keras v3, giving the following error:

Traceback (most recent call last):
  File "M3GNet_Structure_DIRECT_generation_test_Y.py", line 35, in <module>
    m3gnet_struct = M3GNetStructure()  # neither multiprocessing nor Parallel works for this
  File "/work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/maml/describers/_m3gnet.py", line 35, in __init__
    self.describer_model = M3GNet.from_dir(DEFAULT_MODEL)
  File "/work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/m3gnet/models/_m3gnet.py", line 336, in from_dir
    model.load_weights(model_name)
  File "/work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 122, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/keras/src/saving/saving_api.py", line 262, in load_weights
    raise ValueError(
ValueError: File format not supported: filepath=/work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/maml/describers/data/m3gnet_models/matbench_mp_e_form/0/m3gnet/m3gnet. Keras 3 only supports V3 `.keras` and `.weights.h5` files, or legacy V1/V2 `.h5` files.

while downgrading to tensorflow==2.15 and keras<3 fixes this issue. I'm not sure if you want to update the requirements for this, or update the code to work with recent versions.

When fixing all these issues, the code runs, but also throws many warnings:

WARNING:tensorflow:From /work/e05/e05/kavanase/miniconda3/envs/tf_2.14_for_DIRECT/lib/python3.10/site-packages/tensorflow/python/util/deprecation.py:588: calling function (from tensorflow.python.eager.polymorphic_function.polymorphic_function) with experimental_relax_shapes is deprecated and will be removed in a future version.
Instructions for updating:
experimental_relax_shapes is deprecated, use reduce_retracing instead
WARNING:tensorflow:You are casting an input of type complex64 to an incompatible dtype float32.  This will discard the imaginary part and may not be what you intended.
... (many repeats of this)
WARNING:tensorflow:You are casting an input of type complex64 to an incompatible dtype float32.  This will discard the imaginary part and may not be what you intended.
WARNING:tensorflow:You are casting an input of type complex64 to an incompatible dtype float32.  This will discard the imaginary part and may not be what you intended.
WARNING:tensorflow:You are casting an input of type complex64 to an incompatible dtype float32.  This will discard the imaginary part and may not be what you intended.
WARNING:tensorflow:Detecting that an object or model or tf.train.Checkpoint is being deleted with unrestored values. See the following logs for the specific values in question. To silence these warnings, use `status.expect_partial()`. See https://www.tensorflow.org/api_docs/python/tf/train/Checkpoint#restorefor details about the status object returned by the restore function.
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).final.layers.1.pipe.layers.0.kernel
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).final.layers.1.pipe.layers.0.bias
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).final.layers.1.pipe.layers.1.kernel
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).final.layers.1.pipe.layers.1.bias
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).final.layers.1.pipe.layers.2.kernel
WARNING:tensorflow:Value in checkpoint could not be found in the restored object: (root).final.layers.1.pipe.layers.2.bias
coderabbitai[bot] commented 3 months ago

Walkthrough

The changes in setup.py involve updating the paths for package data related to the maml package. Specifically, the paths for MegNet model files have been modified to ensure they point to the correct directories. This adjustment enhances the accuracy and functionality of the package's data management.

Changes

File Change Summary
setup.py Updated package data paths for maml package, changing paths for MegNet model files from "describers/data/megnet_models/*.json" to "describers/data/megnet_models/*" and from "describers/data/megnet_mdoels/*.hdf5" to "describers/data/m3gnet_models/matbench_mp_e_form/0/m3gnet/*".

Recent review details **Configuration used: .coderabbit.yaml** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 8d124babe38fbce7895ac167bf8ff7e8b8b66644 and 5f951568530897cb1fbbfe92dae8ee42c2916862.
Files selected for processing (1) * setup.py (1 hunks)
Additional comments not posted (1)
setup.py (1)
`125-126`: The changes to `package_data` look correct and should resolve the issue with missing model data for `M3GNetStructure`. Please ensure to verify that these files are correctly included in the built package.
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
shyuep commented 3 months ago

Thanks