Skip to content

Commit

Permalink
Added testing for namespace module support
Browse files Browse the repository at this point in the history
  • Loading branch information
eacharles committed Aug 11, 2022
1 parent ad746a7 commit 6303f56
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 60 deletions.
54 changes: 1 addition & 53 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ unsafe-load-any-extension=no
# run arbitrary code
extension-pkg-whitelist=

# Allow optimization of some AST trees. This will activate a peephole AST
# optimizer, which will apply various small optimizations. For instance, it can
# be used to obtain the result of joining multiple strings with the addition
# operator. Joining a lot of strings can lead to a maximum recursion error in
# Pylint and this flag can prevent that. It has one side effect, the resulting
# AST will be different than the one from reality.
optimize-ast=no


[MESSAGES CONTROL]

Expand All @@ -60,7 +52,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating,abstract-method,broad-except,invalid-name,line-too-long,wrong-import-order,wrong-import-position,too-many-statements,super-with-arguments,import-outside-toplevel,too-many-arguments,too-many-instance-attributes,unspecified-encoding,no-else-return
disable=suppressed-message,abstract-method,broad-except,invalid-name,line-too-long,wrong-import-order,wrong-import-position,too-many-statements,super-with-arguments,import-outside-toplevel,too-many-arguments,too-many-instance-attributes,unspecified-encoding,no-else-return


[REPORTS]
Expand All @@ -70,11 +62,6 @@ disable=import-star-module-level,old-octal-literal,oct-method,print-statement,un
# mypackage.mymodule.MyReporterClass.
output-format=text

# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]".
files-output=no

# Tells whether to display a full report or only the messages
reports=yes

Expand All @@ -92,9 +79,6 @@ evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / stateme

[BASIC]

# List of builtins function names that should not be used, separated by a comma
bad-functions=map,filter,input

# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_

Expand All @@ -111,63 +95,33 @@ include-naming-hint=no
# Regular expression matching correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for function names
function-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct variable names
variable-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for variable names
variable-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct constant names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Naming hint for constant names
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Regular expression matching correct attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for attribute names
attr-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for argument names
argument-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct class attribute names
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Naming hint for class attribute names
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Regular expression matching correct inline iteration names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$

# Naming hint for inline iteration names
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$

# Regular expression matching correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$

# Naming hint for class names
class-name-hint=[A-Z_][a-zA-Z0-9]+$

# Regular expression matching correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Naming hint for module names
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Regular expression matching correct method names
method-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for method names
method-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression which should only match function or class names that do
# not require a docstring.
no-docstring-rgx=^_
Expand Down Expand Up @@ -282,12 +236,6 @@ ignore-long-lines=^\s*(# )?<?https?://\S+>?$
# else.
single-line-if-stmt=no

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,dict-separator

# Maximum number of lines in a module
max-module-lines=2000

Expand Down
5 changes: 5 additions & 0 deletions ceci/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file must exist with these contents
from .stage import PipelineStage

if __name__ == "__main__":
PipelineStage.main()
11 changes: 9 additions & 2 deletions ceci/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ def get_stage(cls, name, module_name=None):
stage = cls.pipeline_stages.get(name)
if stage is None:
if module_name:
print("importing ", module_name)
__import__(module_name)
stage = cls.pipeline_stages.get(name)

Expand Down Expand Up @@ -1299,7 +1298,15 @@ def generate_command(
module = cls.get_module()
module = module.split(".")[0]

flags = [f"{cls.get_module()}.{cls.name}"]
if sys.modules[module].__file__:
# Regular module, stage will be imported with module
flags = [f"{cls.name}"]
else:
# Namescape module, use 'ceci' to the get main
# and specify the full path
flags = [f"{cls.get_module()}.{cls.name}"]
module = 'ceci'

aliases = aliases or {}

for tag, _ in cls.inputs_():
Expand Down
215 changes: 215 additions & 0 deletions ceci_example_namespace/example_stages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
from ceci import PipelineStage
from ceci_example.types import TextFile, YamlFile


class NMshearMeasurementPipe(PipelineStage):
"""
This pipeline element is a template for a shape measurement tool
"""

name = "NMshearMeasurementPipe"
inputs = [("DM", TextFile)]
outputs = [("shear_catalog", TextFile)]
config_options = {"metacalibration": bool, "apply_flag": bool}

def run(self):
# Retrieve configuration:
my_config = self.config
print("Here is my configuration :", my_config)

for inp, _ in self.inputs:
filename = self.get_input(inp)
print(f" shearMeasurementPipe reading from {filename}")
open(filename)

for out, _ in self.outputs:
filename = self.get_output(out)
print(f" shearMeasurementPipe writing to {filename}")
open(filename, "w").write("shearMeasurementPipe was here \n")


class NMPZEstimationPipe(PipelineStage):
name = "NMPZEstimationPipe"
inputs = [("DM", TextFile), ("fiducial_cosmology", TextFile)]
outputs = [("photoz_pdfs", TextFile)]

def run(self):
for inp, _ in self.inputs:
filename = self.get_input(inp)
print(f" PZEstimationPipe reading from {filename}")
open(filename)

for out, _ in self.outputs:
filename = self.get_output(out)
print(f" PZEstimationPipe writing to {filename}")
open(filename, "w").write("PZEstimationPipe was here \n")


class NMWLGCRandoms(PipelineStage):
name = "NMWLGCRandoms"
inputs = [("diagnostic_maps", TextFile)]
outputs = [("random_catalog", TextFile)]

def run(self):
for inp, _ in self.inputs:
filename = self.get_input(inp)
print(f" WLGCRandoms reading from {filename}")
open(filename)

for out, _ in self.outputs:
filename = self.get_output(out)
print(f" WLGCRandoms writing to {filename}")
open(filename, "w").write("WLGCRandoms was here \n")


class NMWLGCSelector(PipelineStage):
name = "NMWLGCSelector"
inputs = [("shear_catalog", TextFile), ("photoz_pdfs", TextFile)]
outputs = [("tomography_catalog", TextFile)]
config_options = {"zbin_edges": [float], "ra_range": [-5.0, 5.0]}

def run(self):
print(self.config)
for inp, _ in self.inputs:
filename = self.get_input(inp)
print(f" WLGCSelector reading from {filename}")
open(filename)

for out, _ in self.outputs:
filename = self.get_output(out)
print(f" WLGCSelector writing to {filename}")
open(filename, "w").write("WLGCSelector was here \n")


class NMSourceSummarizer(PipelineStage):
name = "NMSourceSummarizer"
inputs = [
("tomography_catalog", TextFile),
("photoz_pdfs", TextFile),
("diagnostic_maps", TextFile),
]
outputs = [("source_summary_data", TextFile)]

def run(self):
for inp, _ in self.inputs:
filename = self.get_input(inp)
print(f" SourceSummarizer reading from {filename}")
open(filename)

for out, _ in self.outputs:
filename = self.get_output(out)
print(f" SourceSummarizer writing to {filename}")
open(filename, "w").write("SourceSummarizer was here \n")


class NMSysMapMaker(PipelineStage):
name = "NMSysMapMaker"
inputs = [("DM", TextFile)]
outputs = [("diagnostic_maps", TextFile)]

def run(self):
for inp, _ in self.inputs:
filename = self.get_input(inp)
print(f" SysMapMaker reading from {filename}")
open(filename)

for out, _ in self.outputs:
filename = self.get_output(out)
print(f" SysMapMaker writing to {filename}")
open(filename, "w").write("SysMapMaker was here \n")


class NMWLGCTwoPoint(PipelineStage):
name = "NMWLGCTwoPoint"
inputs = [
("tomography_catalog", TextFile),
("shear_catalog", TextFile),
("diagnostic_maps", TextFile),
("random_catalog", TextFile),
]
outputs = [("twopoint_data", TextFile)]

def run(self):
for inp, _ in self.inputs:
filename = self.get_input(inp)
print(f" WLGCTwoPoint reading from {filename}")
open(filename)

for out, _ in self.outputs:
filename = self.get_output(out)
print(f" WLGCTwoPoint writing to {filename}")
open(filename, "w").write("WLGCTwoPoint was here \n")


class NMWLGCCov(PipelineStage):
name = "NMWLGCCov"
inputs = [
("fiducial_cosmology", TextFile),
("tomography_catalog", TextFile),
("shear_catalog", TextFile),
("source_summary_data", TextFile),
("diagnostic_maps", TextFile),
]
outputs = [("covariance", TextFile)]

def rank_filename(self, rank, size):
filename = self.get_output("covariance")
if size == 1:
fname = filename
else:
fname = f"{filename}.{rank}"
return fname

def run(self):

# MPI Information
rank = self.rank
size = self.size
comm = self.comm

for inp, _ in self.inputs:
filename = self.get_input(inp)
print(f" WLGCCov rank {rank}/{size} reading from {filename}")
open(filename)

filename = self.get_output("covariance")
my_filename = self.rank_filename(rank, size)
print(f" WLGCCov rank {rank}/{size} writing to {my_filename}")
open(my_filename, "w").write(f"WLGCCov rank {rank} was here \n")

#
if comm:
comm.Barrier()

# If needed, concatenate all files
if rank == 0 and size > 1:
f = open(filename, "w")
print(f"Master process concatenating files:")
for i in range(size):
fname = self.rank_filename(i, size)
print(f" {fname}")
content = open(fname).read()
f.write(content)
f.close()


class NMWLGCSummaryStatistic(PipelineStage):
name = "NMWLGCSummaryStatistic"
inputs = [
("twopoint_data", TextFile),
("covariance", TextFile),
("source_summary_data", TextFile),
]
outputs = [("wlgc_summary_data", TextFile)]
parallel = False

def run(self):
for inp, _ in self.inputs:
filename = self.get_input(inp)
print(f" WLGCSummaryStatistic reading from {filename}")
open(filename)

for out, _ in self.outputs:
filename = self.get_output(out)
print(f" WLGCSummaryStatistic writing to {filename}")
open(filename, "w").write("WLGCSummaryStatistic was here \n")
2 changes: 1 addition & 1 deletion do_cover.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python -m pytest --cov=./ceci --cov-report=html tests
python -m pytest --cov=./ceci --cov-branch --cov-report=html tests
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
extras_require={
'parsl': ['flask', 'parsl>=1.0.0'],
'cwl': ['cwlgen>=0.4', 'cwltool>=2.0.20200126090152'],
'test': ['pytest', 'codecov', 'pytest-cov'],
'test': ['pytest', 'codecov', 'pytest-cov', 'pytest-mock', 'mockmpi'],
}
)
9 changes: 9 additions & 0 deletions tests/config_nm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
global:
metacalibration: True

NMshearMeasurementPipe:
apply_flag: False

NMWLGCSelector:
zbin_edges: [0.2, 0.3, 0.5]
ra_range: [-5, 5]
Loading

0 comments on commit 6303f56

Please sign in to comment.