Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion invest_processes/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ maintainers = [
dynamic = ["version"] # the version is provided dynamically by setuptools_scm
dependencies = [
"flask",
"natcap.invest",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer a dependency since download_and_extract_datastack was removed

"pygeoapi>=0.23.4",
"google-cloud-storage"
]
Expand Down
8 changes: 7 additions & 1 deletion invest_processes/src/invest_processes/execute.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import multiprocessing
from pathlib import Path
import textwrap

from invest_processes.utils import download_and_extract_datastack
from pygeoapi.process.base import BaseProcessor, ProcessorExecuteError

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -46,6 +46,8 @@
}
}

CPUS_PER_TASK = 2 # number of cpus per task to submit to sbatch

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c2-standard-4 has 4 vCPUs that correspond to only 2 physical cores. Slurm apparently counts the physical cores, and so we can't request more than 2.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relationship between the physical and virtual cores makes sense, and it also makes me wonder if we might be able to programmatically get the CPUs per task from the state of the environment somehow so that if we change the VM class, we don't also have to remember to update this module-level variable. Is that something we can easily get from the compute environment?



class ExecuteProcessor(BaseProcessor):
"""InVEST execute process"""
Expand Down Expand Up @@ -76,11 +78,15 @@ def create_slurm_script(self, datastack_url, workspace_dir):
json_path = f'{workspace_dir}/datastack/parameters.invest.json'
return textwrap.dedent(f"""\
#!/bin/sh
#SBATCH --cpus-per-task={CPUS_PER_TASK}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default --cpus-per-task is 1, hence why tasks were not being parallelized.


curl -o datastack.tgz "{datastack_url}"
mkdir {workspace_dir}/datastack
tar -xzvf datastack.tgz -C {workspace_dir}/datastack
rm datastack.tgz

eval "$(~/bin/micromamba shell hook -s posix)"
micromamba activate invest_env
MODEL_ID=$(python -c "from natcap.invest import datastack; print(datastack.extract_parameter_set('{json_path}').model_id)")
invest --debug --taskgraph-log-level=DEBUG run \
--datastack {json_path} \
Expand Down
6 changes: 4 additions & 2 deletions invest_processes/src/invest_processes/slurm_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,12 @@ def submit_slurm_job(self, processor, data_dict):
f'Submitting slurm job with the following command:\n{args}')
result = subprocess.run(
args, capture_output=True, text=True, check=True)
LOGGER.info(f'stdout from sbatch: {result.stdout}')

except subprocess.CalledProcessError as e:
raise RuntimeError('Error when submitting slurm job') from e
LOGGER.error('error:')
LOGGER.error(str(e))
LOGGER.error(f'stdout from sbatch: {e.stderr}')
raise RuntimeError(f'Error when submitting slurm job: {e.stderr}') from e

job_id = result.stdout.strip()
LOGGER.info(f"Job submitted successfully with ID: {job_id}")
Expand Down
52 changes: 0 additions & 52 deletions invest_processes/src/invest_processes/utils.py

This file was deleted.

1 change: 0 additions & 1 deletion invest_processes/src/invest_processes/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import textwrap
import time

from invest_processes.utils import download_and_extract_datastack
from pygeoapi.process.base import BaseProcessor, ProcessorExecuteError

LOGGER = logging.getLogger(__name__)
Expand Down
20 changes: 20 additions & 0 deletions invest_processes/startup_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

scl enable gcc-toolset-12 bash

# install micromamba
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj ~/bin/micromamba
eval "$(~/bin/micromamba shell hook -s posix)"
micromamba --version

# create and activate the environment
micromamba create -y -n invest_env python=3.13 gdal
micromamba activate invest_env
pip install setuptools setuptools_scm build cython babel
pip install --no-build-isolation git+https://github.com/natcap/pygeoprocessing.git
pip install --no-build-isolation git+https://github.com/emlys/invest.git@bugfix/2572

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Install the not-yet-released changes that fixed the memory leak issue

invest --version

# activate the environment in future shells
echo 'echo "activating micromamba env"' >> /etc/bashrc
echo 'eval "$(~/bin/micromamba shell hook -s posix)" && micromamba activate invest_env' >> ~/.bashrc
11 changes: 7 additions & 4 deletions slurm_cluster_config/hpc-slurm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,20 @@ module "homefs" {
region = var.region
reserved_ip_range = module.private_service_access.reserved_ip_range
zone = var.zone
size_gb = 2560

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly request the minimum filestore size, 2560 GB.

}

module "debug_nodeset" {
source = "github.com/GoogleCloudPlatform/cluster-toolkit//community/modules/compute/schedmd-slurm-gcp-v6-nodeset?ref=v1.90.0"
allow_automatic_updates = false
labels = var.labels
machine_type = "c2-standard-8"
machine_type = "c2-standard-4"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downgraded for cost savings.

disk_type = "pd-ssd"
name = "debug_nodeset"
node_count_dynamic_max = 4
project_id = var.project_id
region = var.region
startup_script = "/home/bin/startup_script.sh"
subnetwork_self_link = module.network.subnetwork_self_link
zone = var.zone
}
Expand All @@ -87,12 +89,12 @@ module "compute_nodeset" {
allow_automatic_updates = false
bandwidth_tier = "gvnic_enabled"
labels = var.labels
machine_type = "c2-standard-8"
machine_type = "c2-standard-4"
name = "compute_nodeset"
node_count_dynamic_max = 20
project_id = var.project_id
region = var.region
startup_script = "startup_script.sh"
startup_script = "/home/bin/startup_script.sh"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to an absolute path to prevent issues depending where this is run from.

subnetwork_self_link = module.network.subnetwork_self_link
zone = var.zone
}
Expand Down Expand Up @@ -128,7 +130,7 @@ module "slurm_login" {
source = "github.com/GoogleCloudPlatform/cluster-toolkit//community/modules/scheduler/schedmd-slurm-gcp-v6-login?ref=v1.90.0"
enable_login_public_ips = true
labels = var.labels
machine_type = "n2-standard-4"
machine_type = "n2-standard-2"
name_prefix = "slurm_login"
project_id = var.project_id
region = var.region
Expand All @@ -143,6 +145,7 @@ module "slurm_controller" {
enable_controller_public_ips = true
labels = var.labels
login_nodes = flatten([module.slurm_login.login_nodes])
machine_type = "n2-standard-2"
network_storage = flatten([module.homefs.network_storage])
nodeset = flatten([module.h3_partition.nodeset, flatten([module.compute_partition.nodeset, flatten([module.debug_partition.nodeset])])])
nodeset_dyn = flatten([module.h3_partition.nodeset_dyn, flatten([module.compute_partition.nodeset_dyn, flatten([module.debug_partition.nodeset_dyn])])])
Expand Down
15 changes: 11 additions & 4 deletions slurm_cluster_config/login_node_playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,27 @@
- "--exclude=slurm_cluster_config"
- "--exclude=tests"

- name: Move startup script to shared location
become: true
ansible.builtin.shell: |
mkdir /home/bin
mv /home/esoth_stanford_edu/invest-compute/invest_processes/startup_script.sh /home/bin
chmod +x /home/bin/startup_script.sh

- name: Install and launch server
args:
chdir: invest-compute/invest_processes
executable: /bin/bash # Ensure bash is used for shell hooks
ansible.builtin.shell: |
# install micromamba
rm -f bin/micromamba
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba
eval "$(./bin/micromamba shell hook -s posix)"
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj ~/bin/micromamba
eval "$(~/bin/micromamba shell hook -s posix)"
micromamba --version

# create and activate the environment
micromamba create -y -n env python=3.13 gdal natcap.invest==3.17.2
micromamba activate env
micromamba create -y -n server_env python=3.13
micromamba activate server_env
pip install --no-cache-dir --only-binary=:all: pygeoapi
pygeoapi --version

Expand Down
14 changes: 0 additions & 14 deletions slurm_cluster_config/startup_script.sh

This file was deleted.

Loading