Skip to content

Commit

Permalink
Merge pull request #9 from pytorch-lumo/dev1
Browse files Browse the repository at this point in the history
Weakly update 2023.03.13
  • Loading branch information
sailist authored Mar 13, 2023
2 parents 89ac1b4 + 6772eaf commit 575b1c3
Show file tree
Hide file tree
Showing 92 changed files with 5,559 additions and 1,337 deletions.
21 changes: 21 additions & 0 deletions .docstr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
paths: ./src/lumo/
badge: ./images # Path
exclude:

verbose: 3 # int (0-4)
skip_magic: True # Boolean
skip_file_doc: True # Boolean
skip_property: True
skip_init: True # Boolean
#skip_class_def: True # Boolean
skip_private: True # Boolean
follow_links: True # Boolean
accept_empty: True # Boolean
ignore_names_file: .*/test # regex
#fail_under: 90 # int
#percentage_only: True # Boolean
ignore_patterns:
callbacks:
- ".*"
exphook:
- ".*"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@ lumo_temp

wandb
.lumorc.json
docs/
.lumorc.public.json
docs/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![PyPI version](https://badge.fury.io/py/lumo.svg)](https://badge.fury.io/py/lumo)
![Python-Test](https://github.com/pytorch-lumo/lumo/actions/workflows/python-test.yml/badge.svg)
[![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/Lightning-AI/lightning/blob/master/LICENSE)
![Python-doc](./images/docstr_coverage_badge.svg)

`lumo` is a light-weight library to help construct your experiment code, record your experiment results, especially in the field of deep learning.

Expand Down
20 changes: 0 additions & 20 deletions examples/more/screen_str.py

This file was deleted.

11 changes: 5 additions & 6 deletions examples/quick_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def add(x):

db = (
DatasetBuilder()
.add_input("xs", torch.arange(-2500, 2500, dtype=torch.float).unsqueeze(1))
.add_input("ys", torch.arange(-2500, 2500, dtype=torch.float), transform=add)
.add_output("xs", "xs")
.add_output("ys", "ys")
.add_input("xs", torch.arange(-2500, 2500, dtype=torch.float).unsqueeze(1))
.add_input("ys", torch.arange(-2500, 2500, dtype=torch.float), transform=add)
.add_output("xs", "xs")
.add_output("ys", "ys")
)

loader = db.DataLoader(batch_size=params.batch_size, shuffle=True)
Expand Down Expand Up @@ -50,12 +50,11 @@ def add(x):
meter.mean.loss = loss
meter.sum.c = 1
record.record(meter)
logger.inline(record.avg())
logger.inline(record.agg())
logger.newline()

test_data = -torch.arange(1000, dtype=torch.float).unsqueeze(1)
res = model(test_data)


test_ys = test_data * 2
print((res.long() - test_ys.long()).sum())
20 changes: 20 additions & 0 deletions images/docstr_coverage_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ omit = [
'src/lumo/cli/*',
'src/lumo/vis/*',
'src/lumo/decorators/*',
'src/lumo/exp/agent.py',
'src/lumo/analyse/*',
'src/lumo/sketch/*',
'src/lumo/core/record_backend/*',
Expand Down Expand Up @@ -73,6 +74,24 @@ exclude_lines = [
"if 0:",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
# some tricky object that can not well tested.
"except ImportError",
"pass",
"return None",
"break", #

# Hard to test
"class RecordAbort",
"class GitCommit",
"def summary_experiment",
"def plot",
"if torch.cuda.is_available()", # ignore cuda
"if is_dist():", # ignore distribution

# Deprecated method:
"def add_input_transform",
"def add_output_transform",
"raise StopIteration"
]

[tool.coverage.html]
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ dbrecord
packaging
pandas
hydra-core
tensorboard
tensorboard
filelock
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ def extract_version():
keywords='lumo',
packages=find_packages('src'),
entry_points={
'console_scripts': [
'lumo = lumo.cli:main',
]
},
)
2 changes: 1 addition & 1 deletion src/lumo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
"""
__version__ = "0.14.6"
__version__ = "0.15.0"

from .core import Params, ParamsType, MetricType, Meter, Record, TrainStage, BaseParams

Expand Down
10 changes: 5 additions & 5 deletions src/lumo/analyse/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ def flatten_metric(df, *keys: str):

def collect_table_rows(metric_root=None) -> pd.DataFrame:
"""Collect all table_row into a pandas.DataFrame"""
res = []
res = {}
logger = Logger()
exp_map = list_all_metrics(metric_root)
for k, rows in exp_map.items():
# append existing row metrics
global_dic = PDict(os.path.join(metricroot(), f'{k}.dict.sqlite'))
for row in global_dic.values():
res.append(row)
for test_name, row in global_dic.items():
res[test_name] = row

if len(rows) == 0:
continue
Expand All @@ -94,10 +94,10 @@ def collect_table_rows(metric_root=None) -> pd.DataFrame:
continue
global_dic[test_name] = row
shutil.move(row_fn, os.path.join(os.path.dirname(row_fn), f'.{test_name}.pkl'))
res.append(row)
res[test_name] = row
global_dic.flush()

return pd.DataFrame(res)
return pd.DataFrame(list(res.values()))


def replac(df: pd.DataFrame):
Expand Down
9 changes: 8 additions & 1 deletion src/lumo/analyse/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@


def in_(ser, value):
"""pandas operation"""
return ser.apply(lambda x: x in value)


def not_in_(ser, value):
"""pandas operation"""
return ser.apply(lambda x: x not in value)


def first(ser, value):
"""pandas operation"""
return ser.duplicated(value) == False


Expand Down Expand Up @@ -101,16 +104,19 @@ def __repr__(self):
return f'{self.name} {self.op} {self.value}'

def in_(self, lis):
"""condition of `in` operation"""
self.op = 'in'
self.value = set(lis)
return self

def not_in_(self, lis):
"""condition of `.duplicated(value) == False` operation"""
self.op = 'notin'
self.value = set(lis)
return self

def first(self, value):
"""condition of `not in` operation"""
self.op = 'first'
self.value = value
return self
Expand All @@ -121,7 +127,8 @@ def first(self, value):

def filter_by_condition(df: DataFrame, *condition: Compare) -> DataFrame:
"""
简化版的 pipeline,仅用于等式和不等式筛选以及额外支持的 in/not_in 等功能
fdf = filter_by_condition(df,C['contition'] == True, C['c2'] > 1, ... )
Args:
df: padnas.DataFrame instance
*condition: list of `~Compare` instance
Expand Down
56 changes: 56 additions & 0 deletions src/lumo/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import fire


def rerun(test_name, **kwarg):
"""
rerun a test
lumo rerun <test_name>
lumo rerun <test_name> --device=0
Args:
test_name:
Returns:
"""
from lumo.exp.finder import retrieval_experiment
exp = retrieval_experiment(test_name)
if exp is not None:
exp.rerun([f'--{k}={v}' for k, v in kwarg.items()])
else:
exit(1)


def note(test_name, description):
"""
Add note to a test:
lumo note <test_name> description ;
Args:
test_name:
description:
Returns:
"""
print(f"Adding note '{description}' to {test_name}")


def server(port=8080):
"""
Args:
port:
Returns:
"""
print(f"Starting server on port {port}")


def main():
fire.Fire({
'rerun': rerun,
'note': note,
'server': server,
})
5 changes: 5 additions & 0 deletions src/lumo/cli/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import fire
from lumo.cli import main

if __name__ == '__main__':
main()
Loading

0 comments on commit 575b1c3

Please sign in to comment.