elements
Advanced tools
| Metadata-Version: 2.1 | ||
| Name: elements | ||
| Version: 3.18.0.dev1 | ||
| Version: 3.18.0 | ||
| Summary: Building blocks for productive research. | ||
@@ -5,0 +5,0 @@ Home-page: http://github.com/danijar/elements |
@@ -1,2 +0,2 @@ | ||
| __version__ = '3.18.0.dev1' | ||
| __version__ = '3.18.0' | ||
@@ -3,0 +3,0 @@ from .agg import Agg |
@@ -108,3 +108,3 @@ import inspect | ||
| save(path, saveables, self._write) | ||
| if folder: | ||
| if folder and self._write: | ||
| (self._directory / 'latest').write_text(folder) | ||
@@ -159,3 +159,3 @@ self._cleanup() | ||
| assert not exists(path), path | ||
| path.mkdir(parents=True) | ||
| write and path.mkdir(parents=True) | ||
| for name, saveable in saveables.items(): | ||
@@ -166,6 +166,6 @@ try: | ||
| for i, shard in enumerate(data): | ||
| assert i < 1e7, i | ||
| assert i < 1e5, i | ||
| if write: # Iterate even if we're not writing. | ||
| buffer = pickle.dumps(shard) | ||
| (path / f'{name}-{i:06d}.pkl').write_bytes(buffer) | ||
| (path / f'{name}-{i:04d}.pkl').write_bytes(buffer) | ||
| else: | ||
@@ -178,3 +178,3 @@ if write: | ||
| raise | ||
| (path / 'done').write_bytes(b'') | ||
| write and (path / 'done').write_bytes(b'') | ||
@@ -192,3 +192,3 @@ | ||
| saveable.load(data) | ||
| elif (path / f'{name}-000000.pkl') in filenames: | ||
| elif (path / f'{name}-0000.pkl') in filenames: | ||
| shards = [x for x in filenames if x.name.startswith(f'{name}-')] | ||
@@ -195,0 +195,0 @@ shards = sorted(shards) |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: elements | ||
| Version: 3.18.0.dev1 | ||
| Version: 3.18.0 | ||
| Summary: Building blocks for productive research. | ||
@@ -5,0 +5,0 @@ Home-page: http://github.com/danijar/elements |
+49
-36
@@ -9,3 +9,3 @@ import elements | ||
| path = elements.Path(tmpdir) | ||
| foo = Foo(42) | ||
| foo = SaveableMock(42) | ||
| cp = elements.Checkpoint(path) | ||
@@ -19,3 +19,3 @@ cp.foo = foo | ||
| del cp | ||
| foo = Foo(42) | ||
| foo = SaveableMock(42) | ||
| cp = elements.Checkpoint(tmpdir) | ||
@@ -29,3 +29,3 @@ cp.foo = foo | ||
| for restart in range(3): | ||
| foo = Foo(42) | ||
| foo = SaveableMock(42) | ||
| cp = elements.Checkpoint(path, keep=3) | ||
@@ -41,3 +41,3 @@ cp.foo = foo | ||
| cp = elements.Checkpoint(path, keep=keep) | ||
| cp.foo = Foo(0) | ||
| cp.foo = SaveableMock(0) | ||
| for i in range(1, 6): | ||
@@ -56,3 +56,3 @@ cp.foo.value = i | ||
| cp = elements.Checkpoint(path, step=step, keep=3) | ||
| cp.foo = Foo(0) | ||
| cp.foo = SaveableMock(0) | ||
| for _ in range(5): | ||
@@ -68,22 +68,11 @@ cp.foo.value = int(step) | ||
| def test_generator(self, tmpdir): | ||
| class Bar: | ||
| def __init__(self, values): | ||
| self.values = values | ||
| def save(self): | ||
| for value in self.values: | ||
| yield {'value': value} | ||
| def load(self, data): | ||
| for i, shard in enumerate(data): | ||
| self.values[i] = shard['value'] | ||
| path = elements.Path(tmpdir) | ||
| cp = elements.Checkpoint(path) | ||
| cp.bar = Bar([42, 12, 26]) | ||
| cp.foo = GeneratorMock([42, 12, 26]) | ||
| cp.save() | ||
| filenames = set(x.name for x in cp.latest().glob('*')) | ||
| assert filenames == { | ||
| 'bar-000000.pkl', | ||
| 'bar-000001.pkl', | ||
| 'bar-000002.pkl', | ||
| 'foo-0000.pkl', | ||
| 'foo-0001.pkl', | ||
| 'foo-0002.pkl', | ||
| 'done', | ||
@@ -93,5 +82,5 @@ } | ||
| cp = elements.Checkpoint(path) | ||
| cp.bar = Bar([0, 0, 0]) | ||
| cp.foo = GeneratorMock([0, 0, 0]) | ||
| cp.load() | ||
| assert cp.bar.values == [42, 12, 26] | ||
| assert cp.foo.values == [42, 12, 26] | ||
@@ -111,21 +100,23 @@ def test_saveable_inline(self, tmpdir): | ||
| def test_saveable_inherit(self, tmpdir): | ||
| class Bar(elements.Saveable): | ||
| def __init__(self, value): | ||
| super().__init__(['value']) | ||
| self.value = value | ||
| path = elements.Path(tmpdir) | ||
| bar = Bar(42) | ||
| foo = SubclassMock(42) | ||
| cp = elements.Checkpoint(path) | ||
| cp.bar = bar | ||
| cp.foo = foo | ||
| cp.save() | ||
| bar.value = 12 | ||
| foo.value = 12 | ||
| cp.load() | ||
| assert bar.value == 42 | ||
| assert foo.value == 42 | ||
| def test_write(self, tmpdir): | ||
| path = elements.Path(tmpdir) | ||
| cp = elements.Checkpoint(path, write=False) | ||
| cp.foo = SaveableMock(42) | ||
| cp.bar = GeneratorMock([1, 2, 3]) | ||
| cp.save() | ||
| assert list(path.glob('*')) == [] | ||
| def test_path(self, tmpdir): | ||
| path = elements.Path(tmpdir) | ||
| cp = elements.Checkpoint() | ||
| cp.foo = Foo(42) | ||
| cp.foo = SaveableMock(42) | ||
| cp.save(path / 'inner') | ||
@@ -140,4 +131,4 @@ assert set(path.glob('*')) == {path / 'inner'} | ||
| cp = elements.Checkpoint(path) | ||
| cp.foo = Foo(42) | ||
| cp.bar = Foo(12) | ||
| cp.foo = SaveableMock(42) | ||
| cp.bar = SaveableMock(12) | ||
| cp.save(keys=['bar']) | ||
@@ -155,3 +146,3 @@ filenames = set(x.name for x in cp.latest().glob('*')) | ||
| class Foo: | ||
| class SaveableMock: | ||
@@ -166,1 +157,23 @@ def __init__(self, value): | ||
| self.value = data['value'] | ||
| class SubclassMock(elements.Saveable): | ||
| def __init__(self, value): | ||
| super().__init__(['value']) | ||
| self.value = value | ||
| class GeneratorMock: | ||
| def __init__(self, values): | ||
| self.values = values | ||
| def save(self): | ||
| for value in self.values: | ||
| shard = {'value': value} | ||
| yield shard | ||
| def load(self, data): | ||
| for i, shard in enumerate(data): | ||
| self.values[i] = shard['value'] |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
136504
0.26%2962
0.27%