Skip to content

Commit a9b1295

Browse files
lmoyasansJavierGOrdonnez
andcommittedMar 7, 2025·
Reboot with new cookiecutter version, lots of fixes and fix commit history
Co-authored-by: JavierGOrdonnez <[email protected]>
1 parent 416e2c5 commit a9b1295

File tree

12 files changed

+163
-244
lines changed

12 files changed

+163
-244
lines changed
 

‎Makefile

+35-107
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Author: Lucia Moya-Sans
2+
# Author: Lucia Moya Sans
33

44
SHELL = /bin/sh
55
.DEFAULT_GOAL := help
@@ -9,117 +9,59 @@ export VCS_REF := $(shell git rev-parse --short HEAD 2> /dev/null || echo unv
99
export VCS_STATUS := $(if $(shell git status -s 2> /dev/null || echo unversioned repo),'modified/untracked','clean')
1010
export BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
1111

12-
export DOCKER_REGISTRY ?= itisfoundation
1312
export DOCKER_IMAGE_NAME ?= pymorphosonic
14-
export DOCKER_IMAGE_TAG ?= $(shell cat VERSION 2> /dev/null || echo undefined)
15-
13+
export DOCKER_IMAGE_TAG ?= 0.1.0
1614

1715
OSPARC_DIR:=$(CURDIR)/.osparc
1816

1917
APP_NAME := pymorphosonic
2018

19+
# Builds new service version ----------------------------------------------------------------------------
2120

22-
23-
24-
# INTEGRATION -----------------------------------------------------------------
25-
METADATA := .osparc/metadata.yml
26-
27-
28-
.PHONY: VERSION
29-
VERSION: $(METADATA) ## generates VERSION from metadata
30-
# updating $@ from $<
31-
@$(OSPARC_DIR)/bin/ooil get-version --metadata-file $< > $@
32-
33-
service.cli/run: $(METADATA) ## generates run from metadata
34-
# Updates adapter script from metadata in $<
35-
@$(OSPARC_DIR)/bin/ooil run-creator --metadata $< --runscript $@
36-
37-
docker-compose.yml: $(METADATA) ## generates docker-compose
38-
# Injects metadata from $< as labels
39-
@$(OSPARC_DIR)/bin/ooil compose --to-spec-file $@ --metadata $<
40-
41-
42-
43-
# BUILD -----------------------------------------------------------------
44-
45-
define _docker_compose_build
46-
export DOCKER_BUILD_TARGET=$(if $(findstring -devel,$@),development,$(if $(findstring -cache,$@),cache,production)); \
47-
docker compose -f docker-compose.yml build $(if $(findstring -nc,$@),--no-cache,);
48-
endef
49-
50-
51-
.PHONY: build build-devel build-nc build-devel-nc
52-
build build-devel build-nc build-devel-nc: VERSION docker-compose.yml service.cli/run ## builds image
53-
# building image local/${DOCKER_IMAGE_NAME}...
54-
@$(call _docker_compose_build)
55-
56-
define show-meta
57-
$(foreach iid,$(shell docker images */$(1):* -q | sort | uniq),\
58-
docker image inspect $(iid) | jq '.[0] | .RepoTags, .ContainerConfig.Labels, .Config.Labels';)
21+
define _bumpversion
22+
# upgrades as $(subst $(1),,$@) version, commits and tags
23+
@docker run -it --rm -v $(PWD):/${DOCKER_IMAGE_NAME} \
24+
-u $(shell id -u):$(shell id -g) \
25+
itisfoundation/ci-service-integration-library:latest \
26+
sh -c "cd /${DOCKER_IMAGE_NAME} && bump2version --verbose --list --config-file $(1) $(subst $(2),,$@)"
5927
endef
6028

29+
.PHONY: version-patch version-minor version-major
30+
version-patch version-minor version-major: .bumpversion.cfg ## increases service's version
31+
@make compose-spec
32+
@$(call _bumpversion,$<,version-)
33+
@make compose-spec
6134

62-
.PHONY: info-build
63-
info-build: ## displays info on the built image
64-
# Built images
65-
@docker images */$(DOCKER_IMAGE_NAME):*
66-
# Tags and labels
67-
@$(call show-meta,$(DOCKER_IMAGE_NAME))
68-
69-
70-
# TESTS-----------------------------------------------------------------
71-
.PHONY: test tests
72-
test tests: ## runs validation tests
73-
@$(OSPARC_DIR)/bin/ooil test .
74-
75-
76-
77-
# PUBLISHING -----------------------------------------------------------------
35+
.PHONY: compose-spec
36+
compose-spec: ## runs ooil to assemble the docker-compose.yml file
37+
@docker run --rm -v $(PWD):/${DOCKER_IMAGE_NAME} \
38+
-u $(shell id -u):$(shell id -g) \
39+
itisfoundation/ci-service-integration-library:latest \
40+
sh -c "cd /${DOCKER_IMAGE_NAME} && ooil compose"
7841

79-
.PHONY: version-service-patch version-service-minor version-service-major
80-
version-service-patch version-service-minor version-service-major: $(METADATA) ## kernel/service versioning as patch
81-
$(OSPARC_DIR)/bin/ooil bump-version --metadata-file $< --upgrade $(subst version-service-,,$@)
82-
# syncing metadata upstream
83-
@$(MAKE) VERSION
42+
build: | compose-spec ## build docker image
43+
docker compose build
8444

85-
86-
.PHONY: tag-local
87-
tag-local:
88-
docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE_NAME}:$(if $(findstring version,$@),$(DOCKER_IMAGE_NAME),latest) local/$(DOCKER_IMAGE_NAME):production
89-
90-
.PHONY: push push-force push-version push-latest pull-latest pull-version tag-latest tag-version
91-
tag-latest tag-version:
92-
docker tag simcore/services/comp/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(if $(findstring version,$@),$(DOCKER_IMAGE_TAG),latest)
93-
94-
version_valid = $(shell test $$(echo $(DOCKER_IMAGE_TAG) | cut --fields=1 --delimiter=.) -gt 0 > /dev/null && echo "image version is valid")
95-
version_exists = $(shell DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG) > /dev/null && echo "image already exists on $(DOCKER_REGISTRY)")
96-
push push-force: ## pushes (resp. force) services to the registry if service not available in registry.
97-
@$(if $(findstring force,$@),,\
98-
$(if $(call version_valid),$(info version is valid), $(error $(DOCKER_IMAGE_TAG) is not a valid version (major>=1)))\
99-
$(if $(call version_exists),$(error $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG) already exists on $(DOCKER_REGISTRY)), $(info no version found on $(DOCKER_REGISTRY)))\
100-
)
101-
@$(MAKE) push-version;
102-
@$(MAKE) push-latest;
45+
# To test built service locally -------------------------------------------------------------------------
46+
.PHONY: run-local
47+
run-local: ## runs image with local configuration
48+
docker compose --file docker-compose-local.yml up
10349

10450
.PHONY: publish-local
10551
publish-local: ## push to local throw away registry to test integration
10652
docker tag simcore/services/comp/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} registry:5000/simcore/services/comp/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
10753
docker push registry:5000/simcore/services/comp/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)
10854
@curl registry:5000/v2/_catalog | jq
109-
110-
push-latest push-version: ## publish service to registry with latest/version tag
111-
# pushing '$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(if $(findstring version,$@),$(DOCKER_IMAGE_TAG),latest)'...
112-
@$(MAKE) tag-$(subst push-,,$@)
113-
@docker push $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(if $(findstring version,$@),$(DOCKER_IMAGE_TAG),latest)
114-
# pushed '$(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(if $(findstring version,$@),$(DOCKER_IMAGE_TAG),latest)'
115-
116-
pull-latest pull-version: ## pull service from registry
117-
@docker pull $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(if $(findstring version,$@),$(DOCKER_IMAGE_TAG),latest)
118-
11955

56+
.PHONY: help
57+
help: ## this colorful help
58+
@echo "Recipes for '$(notdir $(CURDIR))':"
59+
@echo ""
60+
@awk 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
61+
@echo ""
12062

12163

122-
# COOCKIECUTTER -----------------------------------------------------------------
64+
# COOKIECUTTER -----------------------------------------------------------------
12365

12466
.PHONY: replay
12567
replay: .cookiecutterrc ## re-applies cookiecutter
@@ -130,16 +72,13 @@ replay: .cookiecutterrc ## re-applies cookiecutter
13072
"gh:ITISFoundation/cookiecutter-osparc-service"
13173

13274

133-
13475
.PHONY: info
13576
info: ## general info
13677
# env vars: version control
13778
@echo " VCS_URL : $(VCS_URL)"
13879
@echo " VCS_REF : $(VCS_REF)"
13980
@echo " VCS_STATUS : $(VCS_STATUS)"
14081
# env vars: docker
141-
@echo " DOCKER_REGISTRY : $(DOCKER_REGISTRY)"
142-
@echo " DOCKER_IMAGE_NAME : $(DOCKER_IMAGE_NAME)"
14382
@echo " DOCKER_IMAGE_TAG : $(DOCKER_IMAGE_TAG)"
14483
@echo " BUILD_DATE : $(BUILD_DATE)"
14584
# exe: recommended dev tools
@@ -150,21 +89,10 @@ info: ## general info
15089
@echo ' python : $(shell python3 --version 2>/dev/null || echo not found )'
15190
@echo ' docker : $(shell docker --version)'
15291
@echo ' docker buildx : $(shell docker buildx version)'
153-
@echo ' docker-compose : $(shell docker-compose --version)'
154-
# exe: integration tools
155-
@echo ' ooil version : $(shell $(OSPARC_DIR)/bin/ooil --version)'
156-
157-
92+
@echo ' docker compose : $(shell docker compose --version)'
15893

15994
# MISC -----------------------------------------------------------------
16095

161-
.PHONY: help
162-
help: ## this colorful help
163-
@echo "Recipes for '$(notdir $(CURDIR))':"
164-
@echo ""
165-
@awk --posix 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:space:]_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
166-
@echo ""
167-
16896

16997
.PHONY: clean
17098
git_clean_args = -dxf --exclude=.vscode/
@@ -174,4 +102,4 @@ clean: ## cleans all unversioned files in project and temp files create by this
174102
@git clean -n $(git_clean_args)
175103
@echo -n "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
176104
@echo -n "$(shell whoami), are you REALLY sure? [y/N] " && read ans && [ $${ans:-N} = y ]
177-
@git clean $(git_clean_args)
105+
@git clean $(git_clean_args)

‎docker-compose-local.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: '3.7'
2+
services:
3+
pymorphosonic:
4+
image: simcore/services/comp/pymorphosonic:0.1.0
5+
volumes:
6+
- ${PWD}/validation/input:/tmp/input
7+
- ${PWD}/validation/output:/tmp/output

‎docker-compose.yml

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1+
version: '3.7'
12
services:
23
pymorphosonic:
34
build:
45
context: ./
56
dockerfile: docker/python/Dockerfile
67
labels:
7-
io.simcore.name: '{"name":"PyMorphosonic"}'
8+
io.simcore.name: '{"name":"pymorphosonic"}'
89
io.simcore.thumbnail: '{"thumbnail":"https://github.com/ITISFoundation/osparc-assets/blob/cb43207b6be2f4311c93cd963538d5718b41a023/assets/default-thumbnail-cookiecutter-osparc-service.png?raw=true"}'
9-
io.simcore.description: '{"description":"Computational service for simulations
10-
with Pysonic and Morphosonic"}'
10+
io.simcore.description: '{"description":"pymorphosonic"}'
1111
io.simcore.key: '{"key":"simcore/services/comp/pymorphosonic"}'
1212
io.simcore.version: '{"version":"0.1.0"}'
1313
io.simcore.integration-version: '{"integration-version":"1.0.0"}'
1414
io.simcore.type: '{"type":"computational"}'
15-
io.simcore.authors: '{"authors":[{"name":"Lucia Moya-Sans","email":"moyasans@itis.swiss","affiliation":"ITIS
16-
Research Foundation"}]}'
15+
io.simcore.authors: '{"authors":[{"name":"Lucia Moya Sans","email":"moyasans@itis.swiss","affiliation":"ITIS
16+
Foundation"}]}'
1717
io.simcore.contact: '{"contact":"moyasans@itis.swiss"}'
18-
io.simcore.inputs: '{"inputs":{"input_1":{"displayOrder":1.0,"label":"input_data","description":"Input
19-
data","type":"data:*/*","fileToKeyMap":{"input.zip":"input_1"}}}}'
20-
io.simcore.outputs: '{"outputs":{"output_1":{"displayOrder":1.0,"label":"output_file","description":"The
21-
output 1 description","type":"data:*/*","fileToKeyMap":{"output.zip":"output_1"}}}}'
22-
org.label-schema.build-date: 2025-03-03T20:33:42+0000
18+
io.simcore.inputs: '{"inputs":{"input_1":{"displayOrder":1.0,"label":"input_1_label","description":"Input
19+
files (including a .py file)","type":"data:*/*"}}}'
20+
io.simcore.outputs: '{"outputs":{"output_1":{"displayOrder":1.0,"label":"output_1_label","description":"The
21+
input 1 description","type":"data:*/*"}}}'
22+
org.label-schema.build-date: 2025-03-07T15:38:21+0000
2323
org.label-schema.schema-version: '1.0'
24-
org.label-schema.vcs-ref: ''
25-
org.label-schema.vcs-url: ''
24+
org.label-schema.vcs-ref: 416e2c5b2f336cb7731ed920b2ca83f72c13d4a1
25+
org.label-schema.vcs-url: https://github.com/ITISFoundation/pymorphosonic.git
2626
simcore.service.restart-policy: no-restart
27-
simcore.service.settings: '[{"name":"Resources","type":"Resources","value":{"Limits":{"NanoCPUs":1000000000,"MemoryBytes":2147483648}}}]'
27+
simcore.service.paths-mapping: '{"inputs_path":"/home/scu/work/inputs","outputs_path":"/home/scu/work/outputs"}'
28+
simcore.service.settings: '[{"name":"constraints","type":"string","value":["node.platform.os
29+
== linux"]},{"name":"Resources","type":"Resources","value":{"Limits":{"NanoCPUs":1000000000,"MemoryBytes":2147483648}}}]'
2830
target: production
2931
image: simcore/services/comp/pymorphosonic:0.1.0

‎docker/python/Dockerfile

+13-82
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
FROM python:3.11 AS base
1+
FROM python:3.11 as base
22
#
33
# USAGE:
44
# cd services/pymorphosonic
55
# docker build -f Dockerfile -t pymorphosonic:prod --target production ../../
66
# docker run pymorphosonic:prod
77
#
88

9-
LABEL maintainer=moyasans
9+
LABEL maintainer=lmoyasans
1010

11-
# simcore-user uid=8004(${SC_USER_NAME}) gid=8004(${SC_USER_NAME}) groups=8004(${SC_USER_NAME}) TODO change to scu
11+
# simcore-user uid=8004(${SC_USER_NAME}) gid=8004(${SC_USER_NAME}) groups=8004(${SC_USER_NAME})
1212
ENV SC_USER_ID 8004
1313
ENV SC_USER_NAME scu
1414
RUN adduser --uid ${SC_USER_ID} --disabled-password --gecos "" --shell /bin/sh --home /home/${SC_USER_NAME} ${SC_USER_NAME}
@@ -18,98 +18,29 @@ RUN apt-get update \
1818
jq \
1919
&& rm --recursive --force /var/lib/apt/lists/*
2020

21-
# -------------------------- Build stage -------------------
22-
# Installs build/package management tools and third party dependencies
23-
#
24-
# + /build WORKDIR
25-
#
26-
27-
FROM base AS build
28-
29-
ENV SC_BUILD_TARGET build
30-
31-
# ------------------------------------------------------------------------------------
32-
#TODO:
33-
# uncomment and adapt if build dependencies shall be installed
34-
#RUN apt-get update \
35-
# && apt-get -y install --no-install-recommends \
36-
# gcc \
37-
# git \
38-
# && rm -rf /var/lib/apt/lists/*
39-
40-
# uncomment and adapt if python necessary
41-
#RUN $SC_PIP install --upgrade pip wheel setuptools
42-
# ------------------------------------------------------------------------------------
43-
44-
WORKDIR /build
45-
# defines the output of the build
46-
RUN mkdir --parents /build/bin
47-
# copy src code
48-
COPY --chown=${SC_USER_NAME}:${SC_USER_NAME} src/pymorphosonic src/pymorphosonic
49-
50-
# ------------------------------------------------------------------------------------
51-
#TODO:
52-
# uncomment and adapt if build steps are necessary
53-
# RUN cp -R src/pymorphosonic/* /build/bin
54-
# ------------------------------------------------------------------------------------
55-
56-
# --------------------------Production stage -------------------
57-
# Final cleanup up to reduce image size and startup setup
58-
# Runs as ${SC_USER_NAME} (non-root user)
59-
#
60-
# + /home/${SC_USER_NAME} $HOME = WORKDIR
61-
# + pymorphosonic [${SC_USER_NAME}:${SC_USER_NAME}]
62-
# + docker [${SC_USER_NAME}:${SC_USER_NAME}]
63-
# + service.cli [${SC_USER_NAME}:${SC_USER_NAME}]
64-
#
65-
FROM base AS production
21+
FROM base as production
6622

6723
ENV SC_BUILD_TARGET production
6824
ENV SC_BOOT_MODE production
6925

70-
71-
ENV INPUT_FOLDER="/input" \
72-
OUTPUT_FOLDER="/output"
73-
26+
ENV INPUT_FOLDER="/tmp/input" \
27+
OUTPUT_FOLDER="/tmp/output"
7428

7529
WORKDIR /home/${SC_USER_NAME}
7630

77-
# ------------------------------------------------------------------------------------
78-
#TODO:
79-
# uncomment and adapt to install runtime dependencies
80-
#RUN apt-get update \
81-
# && apt-get -y install --no-install-recommends \
82-
# && rm -rf /var/lib/apt/lists/*
83-
# ------------------------------------------------------------------------------------
31+
RUN pip install -e git+https://github.com/tjjlemaire/PySONIC.git@aff881012b83731e7139aa1994f5dff358525700#egg=pysonic
32+
RUN pip install -e git+https://github.com/tjjlemaire/MorphoSONIC.git@64a0a2325ec8a1cfa90ce5595ea93301e4a1ff91#egg=morphosonic
8433

8534
# copy docker bootup scripts
8635
COPY --chown=${SC_USER_NAME}:${SC_USER_NAME} docker/python/*.sh docker/
36+
# copy src code
37+
COPY --chown=${SC_USER_NAME}:${SC_USER_NAME} src/pymorphosonic src/pymorphosonic
8738
# copy simcore service cli
8839
COPY --chown=${SC_USER_NAME}:${SC_USER_NAME} service.cli/ service.cli/
8940
# necessary to be able to call run directly without sh in front
9041
ENV PATH="/home/${SC_USER_NAME}/service.cli:${PATH}"
91-
92-
# copy binaries from build
93-
COPY --from=build --chown=${SC_USER_NAME}:${SC_USER_NAME} /build/bin pymorphosonic
94-
COPY --chown=${SC_USER_NAME}:${SC_USER_NAME} requirements.txt /app/
95-
COPY --chown=${SC_USER_NAME}:${SC_USER_NAME} PySONIC-1.0.0-py3-none-any.whl /app/
96-
COPY --chown=${SC_USER_NAME}:${SC_USER_NAME} MorphoSONIC-1.0.0-py3-none-any.whl /app/
97-
# HOW TO COPY WHL FILE and txt
98-
99-
100-
RUN pip install --upgrade pip wheel setuptools tqdm lockfile multiprocess boltons openpyxl
101-
RUN pip install -r /app/requirements.txt
102-
RUN pip install /app/PySONIC-1.0.0-py3-none-any.whl
103-
RUN pip install /app/MorphoSONIC-1.0.0-py3-none-any.whl
104-
# ------------------------------------------------------------------------------------
105-
#TODO:
106-
# uncomment and provide a healtchecker if possible
107-
# HEALTHCHECK --interval=30s \
108-
# --timeout=120s \
109-
# --start-period=30s \
110-
# --retries=3 \
111-
# CMD ["healthchecker app"]
112-
# ------------------------------------------------------------------------------------
42+
RUN pip install -r src/pymorphosonic/requirements.txt
11343

11444
ENTRYPOINT [ "/bin/sh", "docker/entrypoint.sh", "/bin/sh", "-c" ]
115-
CMD ["run"]
45+
## only for computational (also the "/bin/sh", "-c" above)
46+
CMD ["run"]

‎service.cli/execute.sh

+9-24
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,20 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
# set sh strict mode
33
set -o errexit
44
set -o nounset
55
IFS=$(printf '\n\t')
6-
INFO="INFO: [$(basename "$0")] "
76

8-
cd /home/scu/pymorphosonic
7+
cd /home/scu/src/pymorphosonic
98

10-
echo "$INFO" "starting service as"
11-
echo "$INFO" " User :$(id "$(whoami)")"
12-
echo "$INFO" " Workdir : $(pwd)"
9+
echo "starting service as"
10+
echo User : "$(id "$(whoami)")"
11+
echo Workdir : "$(pwd)"
12+
echo "..."
13+
echo
1314

14-
# Checking for resources limit env vars injected by osparc
15-
SIMCORE_NANO_CPUS_LIMIT="${SIMCORE_NANO_CPUS_LIMIT:-0}"
16-
if [ "${SIMCORE_NANO_CPUS_LIMIT}" -ne "0" ]
17-
then
18-
echo "$INFO" "Found NANO_CPU limits: ${SIMCORE_NANO_CPUS_LIMIT}"
19-
NANO_CPU_DIVISOR=1000000000
20-
MAX_CPUS=$(("${SIMCORE_NANO_CPUS_LIMIT}" / "${NANO_CPU_DIVISOR}"))
21-
# use 1 if this is 0 otherwise floor is probably fine
22-
if [ "${MAX_CPUS}" -eq "0" ]
23-
then
24-
MAX_CPUS=1
25-
fi
26-
echo "$INFO" "Setting Z43_MAX_CPU_RESOURCES to " "${MAX_CPUS}"
27-
export Z43_MAX_CPU_RESOURCES="${MAX_CPUS}"
28-
export OMP_NUM_THREADS="${MAX_CPUS}"
29-
fi
15+
# ----------------------------------------------------------------
3016

3117
env
32-
3318
python3 main.py setup
3419
/bin/sh main.sh
35-
python3 main.py teardown
20+
python3 main.py teardown

‎src/pymorphosonic/main.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
from pathlib import Path
99

1010
logging.basicConfig(level=logging.INFO)
11-
logger = logging.getLogger("s4l-python-main")
12-
11+
logger = logging.getLogger("pymorphosonic")
1312

1413
ENVIRONS = ["INPUT_FOLDER", "OUTPUT_FOLDER"]
1514
try:
1615
input_dir, output_dir = [Path(os.environ.get(v, None)) for v in ENVIRONS]
1716
except KeyError:
1817
raise ValueError("Required env vars {ENVIRONS} were not set")
19-
20-
# TODO: sync with schema in metadata!!
2118
OUTPUT_FILE = "output_data.zip"
2219

2320

@@ -90,12 +87,7 @@ def ensure_requirements(code_dir: Path) -> Path:
9087
# deduce requirements using pipreqs
9188
logger.info("Not found. Recreating requirements ...")
9289
requirements = code_dir / "requirements.txt"
93-
# TODO: MaG This currently does not work for XCore and friends
94-
# run_cmd(f"pipreqs --savepath={requirements} --force {code_dir}")
9590
run_cmd(f"touch {requirements}")
96-
97-
# TODO log subprocess.run
98-
9991
else:
10092
requirements = requirements[0]
10193
return requirements
@@ -110,7 +102,7 @@ def setup():
110102
# NOTE The inputs defined in ${INPUT_FOLDER}/inputs.json are available as env variables by their key in capital letters
111103
# For example: input_1 -> $INPUT_1
112104
#
113-
105+
114106
logger.info("Processing input ...")
115107
unzip_dir(input_dir)
116108

@@ -125,13 +117,15 @@ def setup():
125117
requirements_txt = ensure_requirements(input_dir)
126118

127119
logger.info("Preparing launch script ...")
128-
venv_dir = Path(os.getenv("SC_PYTHON_VENV_ROOT_DIR"))
120+
venv_dir = Path.home() / ".venv"
129121
# TODO: pipreqs tries to download XCore. Can that be avoided?
130122
script = [
131123
"#!/bin/sh",
132124
"set -o errexit",
133125
"set -o nounset",
134126
"IFS=$(printf '\\n\\t')",
127+
'echo "Creating virtual environment ..."',
128+
f'python3 -m venv --system-site-packages --symlinks --upgrade "{venv_dir}"',
135129
f'echo Installing requirements from "{requirements_txt}"',
136130
f"echo Currently installed packages:",
137131
f'"{venv_dir}"/bin/pip list',
@@ -181,4 +175,4 @@ def teardown():
181175
else:
182176
teardown()
183177
except Exception as err: # pylint: disable=broad-except
184-
logger.error("%s . Stopping %s", err, action)
178+
logger.error("%s . Stopping %s", err, action)

‎src/pymorphosonic/requirements.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tqdm>=4.3
2+
lockfile>=0.1.2
3+
multiprocess>=0.70
4+
boltons>=20.1.0
5+
openpyxl
6+
jupyterlab
7+
# matplotlib requirements
8+
contourpy==1.3.0
9+
matplotlib==3.7.3

‎validation/input/input.json

-3
This file was deleted.

‎validation/input/main.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import pickle
2+
3+
from PySONIC.core import PulsedProtocol, BalancedPulsedProtocol
4+
from PySONIC.utils import logger
5+
6+
from MorphoSONIC.models import SennFiber
7+
from MorphoSONIC.sources import *
8+
from MorphoSONIC.plt import *
9+
10+
11+
# class GammaAcousticSource(GammaSource, AbstractAcousticSource):
12+
13+
# def __init__(self, gamma_dict, f, A=None):
14+
# GammaSource.__init__(self, gamma_dict, f=f)
15+
# AbstractAcousticSource.__init__(self, f, A=A)
16+
17+
# def computeDistributedAmps(self, fiber):
18+
# return {k: self.A*v for k,v in GammaSource.computeDistributedAmps(self,fiber).items()}
19+
20+
# def copy(self):
21+
# return self.__class__(self.gamma_dict, self.f, A=self.A)
22+
23+
# @staticmethod
24+
# def inputs():
25+
# return {**GammaSource.inputs(), **AbstractAcousticSource.inputs()}
26+
27+
# a = 3.2e-08
28+
# fs = 1.0
29+
# input_path = "/home/scu/work/inputs/input_1"
30+
31+
# with open(input_path+'/axon_details','rb') as f:
32+
# axondetails = pickle.load(f)
33+
# with open(input_path+'/gamma_dicts','rb') as f:
34+
# gamma_dicts = pickle.load(f)
35+
36+
# fiberD = [ad[2] for ad in axondetails]
37+
# nnodes = [len(ad[3]) for ad in axondetails]
38+
39+
# # Create fiber models
40+
# fibers = [SennFiber(fiberD, nnodes=nnodes, a=a, fs=fs) for fiberD, nnodes in zip(fiberD, nnodes)]
41+
42+
# tpulse = 0.0001
43+
# toffset = 0.0005
44+
# pp = PulsedProtocol(tpulse, toffset)
45+
46+
# gamma_source = [GammaAcousticSource(gamma_dict, f=500000.0, A=100000.0) for gamma_dict in gamma_dicts]
47+
48+
# data_meta_list = []
49+
# for fiber, source in zip(fibers, gamma_source): # TODO can be setted to a number
50+
# # Simulate model with each source-protocol pair, and plot results
51+
# data, meta = fiber.simulate(source, pp)
52+
# #SectionCompTimeSeries([(data, meta)], 'Vm', fiber.nodeIDs).render()
53+
# data_meta_list.append((data, meta))
54+
55+
# output_path = "/home/jovyan/work/outputs/output_1"
56+
# with open(output_path+'/neuron_sims.pickle','wb') as f:
57+
# pickle.dump(data_meta_list,f)
58+
59+
print("Hello World")
60+

‎validation/input/requirements.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tqdm>=4.3
2+
lockfile>=0.1.2
3+
multiprocess>=0.70
4+
boltons>=20.1.0
5+
openpyxl
6+
jupyterlab
7+
# matplotlib requirements
8+
contourpy==1.3.0
9+
matplotlib==3.7.3

‎validation/input/weird_zip_name.zip

1.19 KB
Binary file not shown.

‎validation/output/output.json

-3
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.