Add a notebook#35
Conversation
fnattino
left a comment
There was a problem hiding this comment.
Nice work @SarahAlidoost, looks very clear to me! I have left only a few minor comments below.
michielkallenberg
left a comment
There was a problem hiding this comment.
I had a look at the code.
One suggestion; Perhaps it may be appreciated if it could be run on e.g. google-colab.
[](https://colab.research.google.com/github/WUR-AI/diffWOFOST/blob/add_nb/docs/notebooks/optimization.ipynb)
and then this cell to install packages....
from mpmath import hyper
import os
import sys
import subprocess # Added for subprocess
# Clone the repository
!rm -rf diffWOFOST/
!git clone -b add_nb https://github.com/WUR-AI/diffWOFOST.git
# Change directory
%cd diffWOFOST
# Get the absolute path of the project root *after* changing directory
PROJECT_ROOT = os.getcwd()
# Install poetry if needed.
!pip install -qqq poetry
# Configure poetry to create virtual environments in the project directory
!poetry config virtualenvs.in-project true
# Install project dependencies
# This step may take some time (e.g., 5 minutes)
!poetry install --quiet --all-extras
# 1. Add the project root to sys.path
if PROJECT_ROOT not in sys.path:
sys.path.insert(0, PROJECT_ROOT)
print(f"✅ Added project root {PROJECT_ROOT} to sys.path")
# 1b. Add the 'src' directory (needed because the package lives inside src/)
SRC_PATH = os.path.join(PROJECT_ROOT, "src")
if os.path.exists(SRC_PATH) and SRC_PATH not in sys.path:
sys.path.insert(0, SRC_PATH)
print(f"✅ Added src path {SRC_PATH} to sys.path")
else:
print(f"⚠️ Warning: src path {SRC_PATH} does not exist or already in sys.path")
# 2. Get the path to the site-packages directory of the poetry virtual environment
try:
venv_path_output = subprocess.check_output(
['poetry', 'env', 'info', '--path']
).decode('utf-8').strip()
python_version_major_minor = f"python{sys.version_info.major}.{sys.version_info.minor}"
SITE_PACKAGES_PATH = os.path.join(
venv_path_output, 'lib', python_version_major_minor, 'site-packages'
)
except Exception as e:
print(f"❌ Could not determine poetry venv site-packages path using 'poetry env info': {e}")
print("Attempting a common fallback path structure...")
SITE_PACKAGES_PATH = os.path.abspath(
os.path.join('.venv', 'lib', f'python{sys.version_info.major}.{sys.version_info.minor}', 'site-packages')
)
# 3. Add the site-packages directory to sys.path
if os.path.exists(SITE_PACKAGES_PATH) and SITE_PACKAGES_PATH not in sys.path:
sys.path.insert(0, SITE_PACKAGES_PATH)
print(f"✅ Added {SITE_PACKAGES_PATH} to sys.path")
else:
print(f"⚠️ Warning: Could not find site-packages at {SITE_PACKAGES_PATH} or it's already in sys.path.")then continue with the existing code.
Thanks for the suggestion. I will add the colab badge to the documentation when working on #33. I added a cell to install the package using pip, so there is no need to clone the repository. |
|
can you please approve this? Then I merge it. The failing sonar is due to "coverage" because I moved the helper functions (used in tests too) to the utils module. Since the utils will be changed, I will skip adding tests. |


closes #17
The notebook is
docs/notebooks/optimization.ipynb🔴 To reviewers, please install the package from this branch to be able to run the notebook. Because the latest version is not on pypi yet.