-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix the documentation #333
Conversation
WalkthroughThe pull request introduces updates to the Sphinx documentation configuration and several Jupyter notebooks within the SMACT project. Key changes include incrementing version numbers in Changes
Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Outside diff range and nitpick comments (9)
docs/examples/oxidation_states.ipynb (2)
93-93
: Consider enhancing output formattingThe print statements could benefit from improved formatting:
- Remove the leading space in the f-string
- Consider adding proper formatting for the probability value (e.g.,
.2f
)- f" The probability of Al existing in a 3+ oxidation state with O in a 2- oxidation state is {ox_prob_finder.pair_probability(Al,O)}\"\n", + f"The probability of Al existing in a 3+ oxidation state with O in a 2- oxidation state is {ox_prob_finder.pair_probability(Al,O):.2f}"Also applies to: 102-102
176-183
: Enhance documentation for the structure creation exampleThe CsPbI3 structure creation example would benefit from additional documentation:
- Add comments explaining the choice of space group
- Document the significance of the lattice parameter
- Explain the rationale behind the atomic positions
# Create the structure CsPbI3 = Structure.from_spacegroup( -'Pm-3m', # Spacegroup for a cubic perovskite -Lattice.cubic(6.41), # Cubic spacing of 6.41 Å -['Pb2+', 'Cs+', 'I-'], # Unique species of the ABX3 compound -[[0.,0.,0.],[0.5,0.5,0.5],[0.,0.,0.5]] # Fractional atomic coordinates of each site +'Pm-3m', # Space group Pm-3m (#221) - typical for cubic perovskites +Lattice.cubic(6.41), # Experimental lattice parameter of 6.41 Å at room temperature +['Pb2+', 'Cs+', 'I-'], # Species in the ABX3 perovskite structure (CsPbI3) +[[0.,0.,0.], # Pb at corner (0,0,0) + [0.5,0.5,0.5], # Cs at body centre (1/2,1/2,1/2) + [0.,0.,0.5]] # I at face centres (0,0,1/2), (0,1/2,0), (1/2,0,0)docs/tutorials/crystal_space.ipynb (1)
79-79
: Consider using a specific version tag instead of masterWhilst the installation command correctly includes the crystal_space feature, using the master branch may lead to reproducibility issues as the codebase evolves. Consider pinning to a specific version tag.
- !pip install "smact[crystal_space] @ git+https://github.com/WMD-group/SMACT.git@master" --quiet + !pip install "smact[crystal_space] @ git+https://github.com/WMD-group/SMACT.git@v2.3.0" --quietdocs/tutorials/crystal_space_visualisation.ipynb (1)
68-68
: Consider using PyPI installation for production tutorialsThe current installation command uses a direct git repository URL, which is suitable for development but may not be ideal for production tutorials. Consider using PyPI once the changes are released:
- !pip install "smact[crystal_space] @ git+https://github.com/WMD-group/SMACT.git@master" --quiet + !pip install "smact[crystal_space]" --quietAdditionally, installing from the master branch could expose users to unstable changes. Consider using a specific release tag or commit hash for better reproducibility.
docs/tutorials/smact_generation_of_solar_oxides.ipynb (3)
Line range hint
1-24
: Consider adding environment setup instructionsThe notebook begins with prerequisites but doesn't specify Python version requirements or environment setup steps. Given that the PR was tested with Python 3.10, this information would be valuable for users.
Add the following markdown cell after the prerequisites section:
### Environment Setup This notebook has been tested with Python 3.10 on macOS. To set up your environment: 1. Create a new virtual environment: ```bash python -m venv smact_env source smact_env/bin/activate # On Windows: smact_env\Scripts\activate
- Install the required packages:
pip install "smact[featurisers]"
--- Line range hint `229-272`: **Add error handling for multiprocessing operations** The `process_element_combinations` function could benefit from error handling to manage potential exceptions during parallel processing. Consider updating the function with this implementation: ```diff def process_element_combinations(all_el_combos): """ Process all element combinations using multiprocessing. This function applies the smact_filter to all element combinations using a multiprocessing pool to improve performance. Args: all_el_combos (iterable): An iterable of element combinations. Returns: list: A flattened list of all compounds that pass the SMACT criteria. + + Raises: + RuntimeError: If parallel processing encounters an error. """ - with multiprocessing.Pool() as p: - # Apply smact_filter to all element combinations in parallel - result = p.map(smact_filter, all_el_combos) + try: + with multiprocessing.Pool() as p: + # Apply smact_filter to all element combinations in parallel + result = p.map(smact_filter, all_el_combos) + except Exception as e: + raise RuntimeError(f"Error during parallel processing: {str(e)}") # Flatten the list of results flat_list = [item for sublist in result for item in sublist] return flat_list
Line range hint
334-394
: Consider memory optimisation for large datasetsThe
add_descriptors
function processes over a million rows, which could lead to memory issues. Consider implementing batch processing.Here's a suggested approach:
- Process the data in chunks:
def add_descriptors_in_batches(data, batch_size=10000): """ Process the data in batches to manage memory usage. Args: data (pd.DataFrame): Input DataFrame batch_size (int): Number of rows to process at once Returns: pd.DataFrame: Processed DataFrame """ results = [] for i in range(0, len(data), batch_size): batch = data.iloc[i:i+batch_size].copy() processed_batch = add_descriptors(batch) results.append(processed_batch) return pd.concat(results, ignore_index=True)
- Update the notebook to use this function:
# Apply the function to add descriptors in batches new_data = add_descriptors_in_batches(new_data)docs/tutorials/smact_validity_of_GNoMe.ipynb (2)
209-209
: Consider using a more robust data path structureThe current data path uses an explicit Git reference which might be unnecessary. Consider:
- Using a versioned data path
- Adding error handling for data loading
-data_path = "https://raw.githubusercontent.com/WMD-group/SMACT/refs/heads/master/docs/tutorials/stable_materials_hull.csv" +data_path = "https://raw.githubusercontent.com/WMD-group/SMACT/master/docs/tutorials/stable_materials_hull.csv" + +def load_data(url): + try: + return pd.read_csv(url) + except Exception as e: + print(f"Error loading data: {e}") + return None + +df = load_data(data_path) +if df is None: + raise SystemExit("Failed to load required data")
240-245
: Enhance visualization with better configuration and error handlingThe visualization uses hardcoded values and lacks error handling. Consider extracting plot configuration and adding try-catch blocks.
+# Plot configuration +PLOT_CONFIG = { + 'figsize': (8, 6), + 'title': 'GNoME analysis', + 'xlabel': 'Number of materials', + 'rotation': 45, + 'margin': 1.1 # Right margin multiplier +} + +def create_comparison_plot(df, config=PLOT_CONFIG): + try: + bar_labels = ["GNoME stable materials", "GNoME - SMACT valid"] + counts = [len(df), df["smact_valid"].sum()] + + fig, ax = plt.subplots(figsize=config['figsize']) + bars = ax.barh(bar_labels, counts) + ax.bar_label(bars) + ax.set_xlabel(config['xlabel']) + ax.set_title(config['title']) + plt.xticks(rotation=config['rotation']) + ax.set_xlim(right=max(counts) * config['margin']) + plt.tight_layout() + return fig + except Exception as e: + print(f"Error creating plot: {e}") + return None + +fig = create_comparison_plot(df) +if fig: + plt.show()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (7)
docs/conf.py
(2 hunks)docs/examples/oxidation_states.ipynb
(6 hunks)docs/tutorials/crystal_space.ipynb
(2 hunks)docs/tutorials/crystal_space_visualisation.ipynb
(2 hunks)docs/tutorials/smact_generation_of_solar_oxides.ipynb
(1 hunks)docs/tutorials/smact_validity_of_GNoMe.ipynb
(6 hunks)pyproject.toml
(1 hunks)
🔇 Additional comments (7)
docs/examples/oxidation_states.ipynb (2)
20-20
: LGTM: Import statement properly updated
The addition of Lattice
import is well-aligned with its subsequent usage in the structure creation example.
61-61
: Verify completeness of species list
Please ensure that this refined list of species includes all necessary elements for the tutorial examples.
✅ Verification successful
Species list is complete and correctly represents the oxidation states model
The list shown in the notebook is complete and appropriate for the tutorial. It represents the default probability table used by the Oxidation_state_probability_finder
class, and the examples in the notebook (Al³⁺/O²⁻, CaAl₂O₄, and CsPbI₃) all use species that are present in this list. Specifically:
- Al³⁺ is present as 'Al3'
- O²⁻ is present as 'O-2'
- Ca²⁺ is present as 'Ca2'
- Cs⁺ is present as 'Cs1'
- Pb²⁺ is present as 'Pb2'
- I⁻ is present as 'I-1'
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if all species used in examples are present in the list
# Search for Species instantiations in the notebook
rg "Species\([\"'](\w+)" docs/examples/oxidation_states.ipynb
Length of output: 65
Script:
#!/bin/bash
# Let's examine the notebook content to understand the context and usage of species
cat docs/examples/oxidation_states.ipynb
Length of output: 7311
pyproject.toml (1)
84-87
: Verify the integration of new optional dependencies.
Let's ensure the codebase properly handles these optional dependencies.
✅ Verification successful
Optional dependencies appear to be minimally integrated
The codebase shows very limited usage of these optional dependencies:
- Only one reference to ElementEmbeddings found as an adaptation comment in
smact/utils/composition.py
- No direct imports or usage of matminer found
- Both packages are listed only in
pyproject.toml
as optional featurisers
The minimal integration suggests these are truly optional dependencies that don't require additional documentation updates or test coverage.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for imports and usage of matminer and ElementEmbeddings
# Check for imports
echo "Checking for matminer imports..."
rg "^from matminer|^import matminer" -l
echo "Checking for ElementEmbeddings imports..."
rg "^from ElementEmbeddings|^import ElementEmbeddings" -l
# Check for installation instructions in documentation
echo "Checking for installation instructions..."
rg -i "pip install|poetry add|conda install" docs/
# Check for related test files
echo "Checking for related test files..."
fd -g "*test*.py" | xargs rg "matminer|ElementEmbeddings"
Length of output: 1937
Script:
#!/bin/bash
# Let's try a broader search for these dependencies and their usage
# Search for any mention of matminer in Python files
echo "Searching for matminer usage..."
rg "matminer" -t py
# Search for ElementEmbeddings usage
echo "Searching for ElementEmbeddings usage..."
rg "ElementEmbeddings" -t py
# Check setup files for dependency configurations
echo "Checking setup files..."
rg "matminer|ElementEmbeddings" setup.py setup.cfg pyproject.toml
# Check if there are any featuriser-related files
echo "Checking for featuriser files..."
fd -t f "featur" -X cat {}
Length of output: 671
docs/tutorials/crystal_space_visualisation.ipynb (1)
368-368
: Verify kernel availability in documentation build environment
The kernel specification has been updated to "smact_dev", which aligns with the PR's documentation fixes. However, we should ensure this kernel is available in the documentation build environment.
✅ Verification successful
Kernel specification is consistent with installation methods
The kernel name "smact_dev" appears consistently across multiple documentation notebooks, and the repository provides clear installation instructions via both pip and conda-forge. Since the documentation can be built using either installation method, and the kernel name is consistently used across the documentation, this change is appropriate.
- The kernel specification appears in multiple documentation files:
- docs/tutorials/crystal_space_visualisation.ipynb
- docs/tutorials/smact_validity_of_GNoMe.ipynb
- docs/examples/oxidation_states.ipynb
- docs/examples/valence_electron_count.ipynb
- docs/tutorials/crystal_space.ipynb
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if kernel setup instructions exist in the repository
# Look for kernel setup instructions in documentation
rg -i "kernel.*setup|setup.*kernel|smact_dev" docs/
Length of output: 422
Script:
#!/bin/bash
# Check for environment setup or installation instructions
rg -i "environment|install|conda|pip" docs/README.md docs/contributing.md docs/installation.md docs/setup.md 2>/dev/null
# Check root README for environment setup
cat README.md
Length of output: 12569
docs/conf.py (2)
174-174
: Verify repository branch configuration
The repository branch has been changed from "docs_updates" to "master". Let's verify this is the primary branch.
✅ Verification successful
Repository branch configuration is correctly set to "master"
The configuration value "master" in docs/conf.py aligns with the repository's default branch, which has been confirmed to be "master".
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the primary branch name
# Expected: Confirm if "master" is indeed the main branch
# Check default branch name
gh api repos/WMD-group/SMACT --jq '.default_branch'
Length of output: 58
74-74
: Verify version consistency across project files
The version bump from 2.7.0 to 2.8.0 aligns with the breaking changes mentioned in the PR. However, we should ensure this version matches other project files.
Also applies to: 76-76
✅ Verification successful
Version numbers are consistent across project files
The version numbers are properly aligned across the codebase:
- pyproject.toml: version = "2.8"
- docs/conf.py: version = "2.8" and release = "2.8.0"
The version bump from 2.7 to 2.8 is consistently reflected in all relevant configuration files, properly documenting the breaking changes in this release.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check version consistency across project files
# Expected: Version "2.8.0" in pyproject.toml and other version files
# Check version in pyproject.toml
echo "Version in pyproject.toml:"
rg -A 1 'version\s*=' pyproject.toml
# Check version in other common version files
echo -e "\nVersion in other files:"
fd -t f -e py -e txt -e ini "version" | xargs rg -l 'version\s*=\s*["\']2\.8'
Length of output: 416
Script:
#!/bin/bash
# Let's try a different approach to check version consistency
# Check version in pyproject.toml without regex
echo "Version in pyproject.toml:"
cat pyproject.toml | grep -A 1 "version ="
# Check version in conf.py
echo -e "\nVersion in docs/conf.py:"
cat docs/conf.py | grep -A 1 "version ="
# Check release in docs/conf.py
echo -e "\nRelease in docs/conf.py:"
cat docs/conf.py | grep -A 1 "release ="
# Look for any other version files
echo -e "\nOther version-related files:"
fd "version|VERSION"
Length of output: 642
docs/tutorials/smact_validity_of_GNoMe.ipynb (1)
Line range hint 412-426
: Verify compatibility with the new Python version
The kernel has been updated to use Python 3.10.14 in a dedicated "smact_dev" environment. While this is a good practice for development isolation, we should ensure all dependencies support Python 3.10.
✅ Verification successful
Python 3.10 upgrade is compatible with project dependencies
The kernel update to Python 3.10.14 is fully compatible with the project's dependencies:
- The project explicitly requires Python >=3.10 in setup.py
- All requirements files are compiled with Python 3.10
- Core dependencies like numpy, pandas, scipy, and pymatgen have Python 3.10 support
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if dependencies in requirements or setup files specify Python version constraints
# Search for Python version specifications in requirements files
fd -e txt -e in requirements | xargs grep -l "python"
# Search for Python version specifications in setup files
rg "python_requires" -A 5
Length of output: 212
Script:
#!/bin/bash
# Check content of requirements files and Python version specifications
echo "=== docs/requirements.txt ==="
cat docs/requirements.txt
echo -e "\n=== requirements/requirements-py310.txt ==="
cat requirements/requirements-py310.txt
echo -e "\n=== requirements.txt ==="
cat requirements.txt
Length of output: 9144
"\n", | ||
"print(f\"\\nThe compound probability for CsPbI3 is {prob_compound}.\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.8.13 ('smact_tests')", | ||
"display_name": "smact_dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Inconsistent kernel configurations require standardisation
The notebooks in the codebase show significant inconsistencies:
- Multiple kernel names in use: "Python 3 (ipykernel)", "venv", "smact_dev"
- Various Python versions: 3.9.16, 3.10.14, 3.12.4
This mixed configuration could lead to reproducibility issues. Please:
- Standardise the kernel name across all notebooks
- Align Python versions to ensure consistent behaviour
- Update environment setup documentation to reflect the chosen configuration
🔗 Analysis chain
Verify kernel compatibility
The notebook now uses the "smact_dev" kernel with Python 3.10.14. Please ensure:
- The kernel name matches the development environment setup
- All dependencies are compatible with Python 3.10.14
Also applies to: 211-211
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for kernel consistency across notebooks
# Search for kernel specifications in all notebooks
find docs -name "*.ipynb" -exec jq -r '.metadata.kernelspec.display_name' {} \;
Length of output: 277
Script:
#!/bin/bash
# Check Python version specifications in notebooks
find docs -name "*.ipynb" -exec jq -r '.metadata.language_info.version // empty' {} \;
Length of output: 194
@@ -246,7 +245,7 @@ | |||
], | |||
"metadata": { | |||
"kernelspec": { | |||
"display_name": "Python 3 (ipykernel)", | |||
"display_name": "smact_dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Documentation needed for Jupyter notebook environment setup
The smact_dev
kernel is used across multiple notebook files but there's no documentation about setting up the Jupyter environment or creating this specific kernel. While the README covers basic installation via pip and conda, it lacks instructions for notebook users.
- Add documentation for setting up the Jupyter environment with the
smact_dev
kernel - Consider adding this information to the README.md or creating a dedicated notebook setup guide in the docs directory
🔗 Analysis chain
Verify smact_dev kernel documentation
The kernel specification has been changed to smact_dev. Please ensure this kernel is properly documented in the project's setup instructions.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for documentation about smact_dev kernel setup
rg -i "smact_dev|kernel setup|jupyter setup" docs/
Length of output: 421
Script:
#!/bin/bash
# Search for installation or environment setup documentation
rg -i "installation|setup|environment|conda|pip" README.md docs/README.md
# Check if there's a dedicated environment setup file
fd -e yml -e yaml "environment|setup"
# Look for any documentation about Jupyter setup
fd -g "*CONTRIBUTING*" -g "*DEVELOP*" -g "*README*" -X rg -i "jupyter|kernel|notebook"
Length of output: 1753
featurisers = [ | ||
"matminer", | ||
"ElementEmbeddings", | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider consolidating duplicate dependencies and adding version constraints.
The new featurisers
group includes ElementEmbeddings
which is already present in the crystal_space
group. Additionally, the dependencies lack version constraints which could lead to reproducibility issues.
Consider applying these changes:
featurisers = [
- "matminer",
- "ElementEmbeddings",
+ "matminer>=2024.2.20",
+ "ElementEmbeddings>=0.1.0", # Specify appropriate version
]
Also, consider consolidating the ElementEmbeddings
dependency into a shared group to avoid duplication with crystal_space
.
Committable suggestion skipped: line range outside the PR's diff.
@@ -39,8 +39,7 @@ | |||
" IN_COLAB = False\n", | |||
"\n", | |||
"if IN_COLAB:\n", | |||
" !pip install git+https://github.com/WMD-group/SMACT.git --quiet\n", | |||
" !pip install smact pandas pymatgen matminer" | |||
" !pip install \"smact[featurisers] @ git+https://github.com/WMD-group/SMACT.git@documentation_fix\" --quiet\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid referencing specific branches in installation commands
The installation command references the documentation_fix
branch, which may become invalid once the PR is merged. Consider updating it to use the main/master branch or a specific version tag.
Apply this diff to make the installation command more maintainable:
- !pip install "smact[featurisers] @ git+https://github.com/WMD-group/SMACT.git@documentation_fix" --quiet
+ !pip install "smact[featurisers]" --quiet
Committable suggestion skipped: line range outside the PR's diff.
"INFO: Pandarallel will run on 12 workers.\n", | ||
"INFO: Pandarallel will use standard multiprocessing data transfer (pipe) to transfer data between the main process and workers.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add explicit worker configuration for better resource control
The parallel processing configuration shows increased workers (12), but this is implicitly determined. Consider explicitly setting the number of workers based on system resources.
-pandarallel.initialize(progress_bar=True)
+# Set number of workers based on system resources
+import multiprocessing
+n_workers = min(12, multiprocessing.cpu_count())
+pandarallel.initialize(progress_bar=True, nb_workers=n_workers)
Committable suggestion skipped: line range outside the PR's diff.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #333 +/- ##
==========================================
+ Coverage 73.74% 76.46% +2.72%
==========================================
Files 31 31
Lines 2544 2545 +1
==========================================
+ Hits 1876 1946 +70
+ Misses 668 599 -69 ☔ View full report in Codecov by Sentry. |
Fixing the documentation
Description
This PR fixes the paths in the documentation for the notebooks. It also introduces featurisers as optional dependencies
Type of change
How Has This Been Tested?
Test Configuration:
Reviewers
N/A
Checklist
Summary by CodeRabbit
featurisers
in the project configuration, enhancing material science capabilities.