Skip to content

Commit

Permalink
Use Gitlab registry in CI and remove several warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet committed Feb 8, 2022
1 parent 62ed321 commit ab8a526
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 25 deletions.
8 changes: 1 addition & 7 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,16 @@ include:

.tox-template:
# Using the same image as DVF
image: docker-registry-default.ocp.bbp.epfl.ch/bbp-ou-cells/data-validation-framework:latest
image: bbpgitlab.epfl.ch:5050/neuromath/ci/data-validation-framework:latest

.pytest-template:
# Using Kubernetes runner with custom cpu count and memory amount
tags:
- kubernetes
variables:
KUBERNETES_CPU_LIMIT: 4
KUBERNETES_CPU_REQUEST: 4
KUBERNETES_MEMORY_LIMIT: 4Gi
KUBERNETES_MEMORY_REQUEST: 4Gi

lint:
# Using Kubernetes runner with custom memory amount
tags:
- kubernetes
variables:
KUBERNETES_CPU_LIMIT: 1
KUBERNETES_CPU_REQUEST: 1
Expand Down
1 change: 1 addition & 0 deletions requirements/test.pip
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dir-content-diff>=0.2
dir-content-diff-plugins
pytest
pytest-cov
pytest-html
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
package_dir={"": "src"},
python_requires=">=3.8",
install_requires=reqs,
test_requires=test_reqs,
tests_require=test_reqs,
extras_require={"docs": doc_reqs, "test": test_reqs},
classifiers=[
"Development Status :: 2 - Pre-Alpha",
Expand Down
4 changes: 4 additions & 0 deletions src/synthesis_workflow/tasks/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def output(self):
return MorphsDfLocalTarget(PathConfig().synth_morphs_df_path)


@copy_params(
nb_jobs=ParamRef(RunnerConfig),
)
class PlotMorphometrics(WorkflowTask):
"""Plot cell morphometrics for two groups of cells so they can be easily compared.
Expand Down Expand Up @@ -141,6 +144,7 @@ def run(self):
comp_label=self.comp_label,
normalize=self.normalize,
config_features=self.config_features,
n_workers=self.nb_jobs,
)

def output(self):
Expand Down
6 changes: 4 additions & 2 deletions src/synthesis_workflow/vacuum_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def grow_vacuum_morphologies(
otherwise 'M1-M5' from TNS are allowed.
"""
global_gid = 0
vacuum_synth_morphs_df = pd.DataFrame()
# vacuum_synth_morphs_df = pd.DataFrame()
rows = []
for mtype in tqdm(mtypes):
tmd_parameters[mtype]["diameter_params"]["method"] = diametrizer
tmd_distributions["mtypes"][mtype]["diameter"]["method"] = diametrizer
Expand Down Expand Up @@ -112,7 +113,8 @@ def grow_vacuum_morphologies(
)
for gid in gids
):
vacuum_synth_morphs_df = vacuum_synth_morphs_df.append(row)
rows.append(row)
vacuum_synth_morphs_df = pd.concat(rows)
return vacuum_synth_morphs_df


Expand Down
32 changes: 23 additions & 9 deletions src/synthesis_workflow/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,26 @@ def get_features_df(morphologies_mtypes: Dict, features_config: Dict, n_workers:
(see ``neurom.apps.morph_stats.extract_dataframe``)
n_workers (int) : number of workers for feature extractions
"""
features_df = pd.DataFrame()
rows = []
for mtype, morphology_folders in morphologies_mtypes.items():
features_df_tmp = extract_dataframe(
morphology_folders, features_config, n_workers=n_workers
)
features_df_tmp["mtype"] = mtype
features_df = features_df.append(features_df_tmp.replace(0, np.nan))
rows.append(features_df_tmp.replace(0, np.nan))
features_df = pd.concat(rows)
return features_df


def _get_features_df_all_mtypes(morphs_df, features_config, morphology_path):
def _get_features_df_all_mtypes(morphs_df, features_config, morphology_path, n_workers=None):
"""Wrapper for morph-validator functions."""
if n_workers is None:
n_workers = os.cpu_count()
morphs_df_dict = {mtype: df[morphology_path] for mtype, df in morphs_df.groupby("mtype")}
with warnings.catch_warnings():
# Ignore some Numpy warnings
warnings.simplefilter("ignore", category=RuntimeWarning)
return get_features_df(morphs_df_dict, features_config, n_workers=os.cpu_count())
return get_features_df(morphs_df_dict, features_config, n_workers=n_workers)


def get_feature_configs(config_types="default"):
Expand Down Expand Up @@ -158,15 +161,16 @@ def get_feature_configs(config_types="default"):

def _expand_lists(data):
"""Convert list element of dataframe to duplicated rows with float values."""
data_expanded = pd.DataFrame()
new_rows = []
for row_id in data.index:
if isinstance(data.loc[row_id, "value"], list):
for value in data.loc[row_id, "value"]:
new_row = data.loc[row_id].copy()
new_row["value"] = value
data_expanded = data_expanded.append(new_row)
new_rows.append(new_row)
else:
data_expanded = data_expanded.append(data.loc[row_id].copy())
new_rows.append(data.loc[row_id].copy())
data_expanded = pd.DataFrame(new_rows)
return data_expanded


Expand Down Expand Up @@ -247,6 +251,7 @@ def plot_morphometrics(
comp_label="comp",
normalize=False,
config_features=None,
n_workers=None,
):
"""Plot morphometrics.
Expand All @@ -260,14 +265,22 @@ def plot_morphometrics(
comp_label (str): label for the compared morphologies
normalize (bool): normalize data if set to True
config_features (dict): mapping of features to plot
n_workers (int): the number of workers used to compute morphology features
"""
if config_features is None:
config_features = get_feature_configs(config_types="synthesis")
# config_features["neurite"].update({"y_distances": ["min", "max"]})

base_features_df = _get_features_df_all_mtypes(base_morphs_df, config_features, base_key)
L.debug("Get features from base morphologies")
base_features_df = _get_features_df_all_mtypes(
base_morphs_df, config_features, base_key, n_workers=n_workers
)
base_features_df["label"] = base_label
comp_features_df = _get_features_df_all_mtypes(comp_morphs_df, config_features, comp_key)

L.debug("Get features from compared morphologies")
comp_features_df = _get_features_df_all_mtypes(
comp_morphs_df, config_features, comp_key, n_workers=n_workers
)
comp_features_df["label"] = comp_label

base_features_df = base_features_df[
Expand All @@ -280,6 +293,7 @@ def plot_morphometrics(
all_features_df = pd.concat([base_features_df, comp_features_df])
ensure_dir(output_path)
with DisableLogger():
L.debug("Plot violin figure to %s", str(output_path))
plot_violin_features(
all_features_df,
["basal_dendrite", "apical_dendrite"],
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
from subprocess import call

import dir_content_diff.pandas
import dir_content_diff.voxcell
import dir_content_diff_plugins.voxcell
import luigi
import numpy as np
import pytest

from synthesis_workflow.tasks import config
from synthesis_workflow.tools import get_layer_tags

dir_content_diff.pandas.register_pandas()
dir_content_diff.voxcell.register_voxcell()
dir_content_diff.pandas.register()
dir_content_diff_plugins.voxcell.register()


TEST_ROOT = Path(__file__).parent
Expand Down
7 changes: 6 additions & 1 deletion tests/test_O1_workflow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Tests for workflows module."""
import luigi
import numpy as np
import pytest
from dir_content_diff import assert_equal_trees

from synthesis_workflow.tasks.workflows import ValidateSynthesis


@pytest.mark.xdist_group("group_O1")
def test_ValidateSynthesis(small_O1_working_directory, data_dir):
"""Test the synthesis workflow in simple atlas"""
np.random.seed(0)
Expand Down Expand Up @@ -51,6 +53,9 @@ def test_ValidateSynthesis(small_O1_working_directory, data_dir):
"tolerance": 2e-3,
"absolute_tolerance": 1e-15,
},
"validation/morphology_validation_reports/validation_results.json": {"tolerance": 2e-3},
"validation/morphology_validation_reports/validation_results.json": {
"tolerance": 2e-3,
"absolute_tolerance": 1e-12,
},
},
)
2 changes: 2 additions & 0 deletions tests/test_vacuum_workflow.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Tests for workflows module."""
import luigi
import numpy as np
import pytest
from dir_content_diff import assert_equal_trees

from synthesis_workflow.tasks.workflows import ValidateVacuumSynthesis


@pytest.mark.xdist_group("group_vacuum")
def test_ValidateVacuumSynthesis(vacuum_working_directory, data_dir):
"""Test the synthesis workflow in vacuum"""
np.random.seed(0)
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ setenv =
COVERAGE_FILE = {env:COVERAGE_FILE:.coverage-{envname}}
extras = test
commands = pytest \
-n 4 \
--dist loadfile \
-n {env:PYTEST_NPROCS:3} \
--dist loadgroup \
--basetemp={envtmpdir} \
--cov={envsitepackagesdir}/{[base]name} \
--cov={envsitepackagesdir}/{[base]morphval} \
Expand Down Expand Up @@ -85,6 +85,7 @@ commands =
black {[base]files}

[testenv:docs]
basepython=python3.8
changedir = doc
extras = docs
allowlist_externals =
Expand Down

0 comments on commit ab8a526

Please sign in to comment.