Skip to content

Commit

Permalink
poetry update + bugfix (#467)
Browse files Browse the repository at this point in the history
* poetry update + bugfix

* bugfix
  • Loading branch information
PythonFZ authored Dec 15, 2022
1 parent c48a4bf commit 58e8d2b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 22 deletions.
36 changes: 18 additions & 18 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions tests/integration_tests/test_list_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Test for [NodeAttribute] as 'zn.deps'."""
from zntrack import Node, zn


class GenerateOutput(Node):
"""Generate an output."""

inputs: int = zn.params()
output: int = zn.outs()

def run(self):
self.output = self.inputs


class SumNumbers(Node):
"""Sum a list of numbers."""

inputs: list = zn.deps()
shift: int = zn.params()
output: int = zn.outs()

def run(self):
self.output = sum(self.inputs)


def test_list_deps(proj_path):
node1 = GenerateOutput(inputs=1, name="node1")
node2 = GenerateOutput(inputs=1, name="node2")

data = [node1 @ "output", node2 @ "output"]
node3 = SumNumbers(inputs=data, shift=10)

node1.write_graph()
node2.write_graph()
node3.write_graph()
27 changes: 23 additions & 4 deletions zntrack/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,30 @@ def __repr__(self):
)

def __hash__(self):
"""compute the hash based on the parameters and node_name."""
params_dict = self.zntrack.collect(zn_params)
params_dict["node_name"] = self.node_name
"""compute the hash based on the parameters and node_name.
return hash(json.dumps(params_dict, sort_keys=True, cls=znjson.ZnEncoder))
Ignore 'not serializable' here so it will not raise an error.
Returns
-------
hash value based on the parameters and node_name. If there are some errors,
during the collection of the parameters, it will return super hash.
"""
try:
params_dict = self.zntrack.collect(zn_params)
params_dict["node_name"] = self.node_name

return hash(
json.dumps(
params_dict,
sort_keys=True,
cls=znjson.ZnEncoder,
default=lambda o: "<not serializable>",
)
)
except utils.exceptions.GraphNotAvailableError:
return super().__hash__()

def __matmul__(self, other: str) -> typing.Union[NodeAttribute, typing.Any]:
"""Shorthand for: getdeps(Node, other).
Expand Down

6 comments on commit 58e8d2b

@github-actions
Copy link

Choose a reason for hiding this comment

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

Report for Python 3.8

name min max mean stddev median iqr outliers ops rounds iterations
0 tests/benchmark/test_benchmark.py::test_InputOutput_load_lazy 0.000101701 0.000309704 0.000104032 7.57384e-06 0.000103401 7e-07 23;91 9612.43 1242 1
1 tests/benchmark/test_benchmark.py::test_InputOutput_load 0.000104502 0.000202402 0.000106653 3.73369e-06 0.000106101 7e-07 49;93 9376.17 1308 1
2 tests/benchmark/test_benchmark.py::test_NodeCollector_load_lazy 0.000106602 0.00443726 0.000112939 0.000126419 0.000108002 6.99e-07 4;103 8854.32 1184 1
3 tests/benchmark/test_benchmark.py::test_NodeCollector_load 0.000107201 0.00242063 0.00013229 0.000226723 0.000108402 8.005e-07 1;15 7559.13 104 1
4 tests/benchmark/test_benchmark.py::test_NodeCollector_run_and_save 0.000393206 0.0107639 0.00126443 0.00189891 0.000449807 0.000783811 5;8 790.87 46 1
5 tests/benchmark/test_benchmark.py::test_InputOutput_write_graph 0.00148682 0.0770394 0.0018803 0.00392875 0.00158327 9.1001e-05 1;55 531.829 370 1
6 tests/benchmark/test_benchmark.py::test_InputOutput_run_and_save 0.00161842 0.00284244 0.00177742 0.000189361 0.00173777 0.000100902 31;31 562.613 348 1
7 tests/benchmark/test_benchmark.py::test_NodeCollector_write_graph 0.125129 0.441455 0.236813 0.108096 0.218616 0.0524553 2;1 4.22274 6 1

@github-actions
Copy link

Choose a reason for hiding this comment

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

Report for Python 3.9

name min max mean stddev median iqr outliers ops rounds iterations
0 tests/benchmark/test_benchmark.py::test_InputOutput_load_lazy 9.4401e-05 0.00103111 0.00011377 4.95319e-05 0.000107402 1e-06 22;231 8789.64 1331 1
1 tests/benchmark/test_benchmark.py::test_InputOutput_load 0.000103701 0.000290703 0.000105565 6.77559e-06 0.000104901 6e-07 29;107 9472.82 1306 1
2 tests/benchmark/test_benchmark.py::test_NodeCollector_load_lazy 0.000105901 0.0126402 0.000118714 0.000361054 0.000107501 8e-07 1;108 8423.64 1205 1
3 tests/benchmark/test_benchmark.py::test_NodeCollector_load 0.0001063 0.0109871 0.000127655 0.000371216 0.0001078 9.99e-07 4;117 7833.64 1226 1
4 tests/benchmark/test_benchmark.py::test_NodeCollector_run_and_save 0.000415504 0.0183076 0.00125938 0.0027639 0.000459305 0.000174703 5;10 794.042 74 1
5 tests/benchmark/test_benchmark.py::test_InputOutput_write_graph 0.00145621 0.0136893 0.00167403 0.00084944 0.00154046 4.17e-05 10;78 597.36 414 1
6 tests/benchmark/test_benchmark.py::test_InputOutput_run_and_save 0.00155252 0.0154443 0.00169539 0.000915342 0.00159562 4.865e-05 2;48 589.834 351 1
7 tests/benchmark/test_benchmark.py::test_NodeCollector_write_graph 0.176015 0.393977 0.246184 0.0850204 0.216377 0.0659124 1;1 4.062 5 1

@github-actions
Copy link

Choose a reason for hiding this comment

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

Report for Python 3.10

name min max mean stddev median iqr outliers ops rounds iterations
0 tests/benchmark/test_benchmark.py::test_InputOutput_load_lazy 9.6001e-05 0.0126464 0.000108939 0.000359444 9.7802e-05 9e-07 1;100 9179.44 1219 1
1 tests/benchmark/test_benchmark.py::test_InputOutput_load 9.7902e-05 0.0127287 0.000113211 0.000361384 0.000100102 1.1e-06 4;116 8833.03 1236 1
2 tests/benchmark/test_benchmark.py::test_NodeCollector_load 9.8101e-05 0.00889873 0.000111485 0.000284083 9.9701e-05 9.2575e-07 2;88 8969.78 1109 1
3 tests/benchmark/test_benchmark.py::test_NodeCollector_load_lazy 9.8101e-05 0.000251804 0.00010049 5.2462e-06 9.9801e-05 1e-06 42;84 9951.2 1081 1
4 tests/benchmark/test_benchmark.py::test_NodeCollector_run_and_save 0.000363505 0.00893873 0.000640223 0.00098751 0.000472807 0.000137027 3;9 1561.95 79 1
5 tests/benchmark/test_benchmark.py::test_InputOutput_write_graph 0.00144252 0.00799631 0.00163752 0.000397913 0.00151962 0.000211953 21;21 610.678 357 1
6 tests/benchmark/test_benchmark.py::test_InputOutput_run_and_save 0.00157462 0.00296144 0.00177985 0.000219603 0.00168622 0.000191302 55;26 561.844 354 1
7 tests/benchmark/test_benchmark.py::test_NodeCollector_write_graph 0.158444 0.343141 0.226789 0.0705093 0.205748 0.0774786 1;0 4.40939 5 1

@github-actions
Copy link

Choose a reason for hiding this comment

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

Report for Python 3.9

name min max mean stddev median iqr outliers ops rounds iterations
0 tests/benchmark/test_benchmark.py::test_InputOutput_load 9.76e-05 0.000505302 0.000100446 1.02225e-05 9.98e-05 1.199e-06 19;96 9955.56 1689 1
1 tests/benchmark/test_benchmark.py::test_NodeCollector_load_lazy 9.94e-05 0.000205601 0.000102382 4.53008e-06 0.0001018 1.2e-06 54;83 9767.3 1469 1
2 tests/benchmark/test_benchmark.py::test_InputOutput_load_lazy 9.96e-05 0.0001389 0.000101893 2.54595e-06 0.0001014 1.101e-06 88;126 9814.24 1662 1
3 tests/benchmark/test_benchmark.py::test_NodeCollector_load 0.0001 0.000540602 0.000103085 1.49482e-05 0.000101901 1.1e-06 15;97 9700.73 1504 1
4 tests/benchmark/test_benchmark.py::test_NodeCollector_run_and_save 0.000336401 0.000905504 0.000365129 7.78807e-05 0.000342601 2.58003e-05 2;6 2738.76 57 1
5 tests/benchmark/test_benchmark.py::test_InputOutput_write_graph 0.001268 0.00239151 0.00134751 8.63919e-05 0.0013303 4.635e-05 26;31 742.107 395 1
6 tests/benchmark/test_benchmark.py::test_InputOutput_run_and_save 0.00136911 0.00184231 0.00146968 7.02243e-05 0.00145806 0.000100301 107;5 680.42 404 1
7 tests/benchmark/test_benchmark.py::test_NodeCollector_write_graph 0.166695 0.318003 0.224681 0.0585159 0.209912 0.0744979 1;0 4.45076 5 1

@github-actions
Copy link

Choose a reason for hiding this comment

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

Report for Python 3.8

name min max mean stddev median iqr outliers ops rounds iterations
0 tests/benchmark/test_benchmark.py::test_InputOutput_load_lazy 0.000119501 0.00690688 0.000131988 0.000230259 0.000121501 1.3e-06 3;94 7576.47 1163 1
1 tests/benchmark/test_benchmark.py::test_NodeCollector_load 0.000120801 0.000232603 0.000124463 6.60461e-06 0.000123302 1.8e-06 36;68 8034.5 966 1
2 tests/benchmark/test_benchmark.py::test_InputOutput_load 0.000121101 0.00171422 0.000125658 4.84448e-05 0.000123302 1.501e-06 3;78 7958.11 1085 1
3 tests/benchmark/test_benchmark.py::test_NodeCollector_load_lazy 0.000121802 0.000176502 0.000125446 3.61829e-06 0.000124602 2.3e-06 67;58 7971.58 1038 1
4 tests/benchmark/test_benchmark.py::test_NodeCollector_run_and_save 0.000493507 0.00458586 0.000646525 0.000628004 0.000516307 3.84007e-05 2;5 1546.73 45 1
5 tests/benchmark/test_benchmark.py::test_InputOutput_write_graph 0.00174982 0.0948813 0.00210486 0.00511045 0.00179728 4.7848e-05 1;26 475.092 332 1
6 tests/benchmark/test_benchmark.py::test_InputOutput_run_and_save 0.00189842 0.00526846 0.00203851 0.000212463 0.00202432 0.000102826 7;10 490.555 291 1
7 tests/benchmark/test_benchmark.py::test_NodeCollector_write_graph 0.256546 0.413124 0.294837 0.0668276 0.267138 0.0566111 1;1 3.3917 5 1

@github-actions
Copy link

Choose a reason for hiding this comment

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

Report for Python 3.10

name min max mean stddev median iqr outliers ops rounds iterations
0 tests/benchmark/test_benchmark.py::test_NodeCollector_load_lazy 0.000108005 0.00819327 0.000134475 0.000340251 0.000118305 1.87425e-06 2;95 7436.3 959 1
1 tests/benchmark/test_benchmark.py::test_InputOutput_load_lazy 0.000111503 0.000454111 0.000115477 1.18658e-05 0.000114103 1.8e-06 22;77 8659.7 1022 1
2 tests/benchmark/test_benchmark.py::test_InputOutput_load 0.000112705 0.000685732 0.000116676 1.79903e-05 0.000115305 1.7e-06 11;74 8570.77 1080 1
3 tests/benchmark/test_benchmark.py::test_NodeCollector_load 0.000114505 0.000226811 0.000117936 4.9366e-06 0.000117106 1.4e-06 48;77 8479.19 922 1
4 tests/benchmark/test_benchmark.py::test_NodeCollector_run_and_save 0.00042942 0.0102658 0.000869349 0.00168102 0.000472722 7.15538e-05 4;7 1150.29 67 1
5 tests/benchmark/test_benchmark.py::test_InputOutput_write_graph 0.00176358 0.00583847 0.00188677 0.000407815 0.00181898 3.92278e-05 9;28 530.006 313 1
6 tests/benchmark/test_benchmark.py::test_InputOutput_run_and_save 0.00181578 0.0160459 0.00201793 0.000988899 0.00187669 5.9302e-05 6;31 495.557 279 1
7 tests/benchmark/test_benchmark.py::test_NodeCollector_write_graph 0.251553 0.434308 0.299901 0.0767089 0.273977 0.0728148 1;1 3.33444 5 1

Please sign in to comment.