Skip to content

Commit ba3d718

Browse files
committed
temp
1 parent e0ee82c commit ba3d718

File tree

3 files changed

+56
-37
lines changed

3 files changed

+56
-37
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ keywords = ["neuroscience connectomics EM"]
3535
license = {text = "MIT"}
3636
name = "zetta_utils"
3737
readme = "README.md"
38-
requires-python = ">3.10,<3.13"
38+
requires-python = ">3.9,<3.13"
3939
urls = {Homepage = "https://github.com/zettaai/zetta_utils"}
4040
version = "0.0.2"
4141

tests/unit/mazepa/test_id_generation.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -226,49 +226,50 @@ def test_generate_invocation_id_subchunkable_flow() -> None:
226226

227227
def _gen_id_calls(_) -> dict[str, str]:
228228
gen_ids = {
229-
'gen_id(ClassA().method, [], {"a": 1})': gen_id(ClassA().method, [], {"a": 1}),
230-
"gen_id(ClassD1().method, [], {})": gen_id(ClassD1().method, [], {}),
231-
"gen_id(ClassE(1).method, [], {})": gen_id(ClassE(1).method, [], {}),
232-
"gen_id(partial(ClassA().method, 42), [], {})": gen_id(
233-
partial(ClassA().method, 42), [], {}
234-
),
235-
"gen_id(partial(ClassD1().method, 42), [], {})": gen_id(
236-
partial(ClassD1().method, 42), [], {}
237-
),
238-
"gen_id(partial(ClassE(1).method, 42), [], {})": gen_id(
239-
partial(ClassE(1).method, 42), [], {}
240-
),
241-
"gen_id(TaskableA(), [], {})": gen_id(TaskableA(), [], {}),
242-
"gen_id(TaskableD(1), [], {})": gen_id(TaskableD(1), [], {}),
243-
"gen_id(FlowSchema({}, ClassA().method).flow, [], {})": gen_id(
244-
FlowSchema({}, ClassA().method).flow, [], {}
245-
),
246-
"gen_id(FlowSchema({}, ClassD1().method).flow, [], {})": gen_id(
247-
FlowSchema({}, ClassD1().method).flow, [], {}
248-
),
249-
"gen_id(FlowSchema({}, ClassE(1).method).flow, [], {})": gen_id(
250-
FlowSchema({}, ClassE(1).method).flow, [], {}
251-
),
252-
"gen_id(subchunkable_flow(), [], {})": gen_id(
253-
subchunkable_flow().fn, subchunkable_flow().args, subchunkable_flow().kwargs
254-
),
229+
# 'gen_id(ClassA().method, [], {"a": 1})': gen_id(ClassA().method, [], {"a": 1}),
230+
"gen_id(ClassD1().method, [], {})": gen_id(ClassD1().method, [], {}, None, True),
231+
# "gen_id(ClassE(1).method, [], {})": gen_id(ClassE(1).method, [], {}),
232+
# "gen_id(partial(ClassA().method, 42), [], {})": gen_id(
233+
# partial(ClassA().method, 42), [], {}
234+
# ),
235+
# "gen_id(partial(ClassD1().method, 42), [], {})": gen_id(
236+
# partial(ClassD1().method, 42), [], {}
237+
# ),
238+
# "gen_id(partial(ClassE(1).method, 42), [], {})": gen_id(
239+
# partial(ClassE(1).method, 42), [], {}
240+
# ),
241+
# "gen_id(TaskableA(), [], {})": gen_id(TaskableA(), [], {}),
242+
# "gen_id(TaskableD(1), [], {})": gen_id(TaskableD(1), [], {}),
243+
# "gen_id(FlowSchema({}, ClassA().method).flow, [], {})": gen_id(
244+
# FlowSchema({}, ClassA().method).flow, [], {}
245+
# ),
246+
# "gen_id(FlowSchema({}, ClassD1().method).flow, [], {})": gen_id(
247+
# FlowSchema({}, ClassD1().method).flow, [], {}
248+
# ),
249+
# "gen_id(FlowSchema({}, ClassE(1).method).flow, [], {})": gen_id(
250+
# FlowSchema({}, ClassE(1).method).flow, [], {}
251+
# ),
252+
# "gen_id(subchunkable_flow(), [], {})": gen_id(
253+
# subchunkable_flow().fn, subchunkable_flow().args, subchunkable_flow().kwargs
254+
# ),
255255
}
256256
return gen_ids
257257

258258

259259
def test_persistence_across_sessions() -> None:
260260
# Create two separate processes - spawn ensures a new PYTHONHASHSEED is used
261261
ctx = multiprocessing.get_context("spawn")
262-
with ctx.Pool(processes=2) as pool:
263-
result = pool.map(_gen_id_calls, range(2))
264-
265-
assert result[0] == result[1]
262+
for _ in range(1):
263+
with ctx.Pool(processes=2) as pool:
264+
result = pool.map(_gen_id_calls, range(2))
266265

266+
assert result[0] == result[1]
267267

268-
def test_unpickleable_fn(mocker) -> None:
269-
# See https://github.com/uqfoundation/dill/issues/147 and possibly
270-
# https://github.com/uqfoundation/dill/issues/56
271268

272-
unpickleable_fn = mocker.MagicMock()
269+
"""
270+
def test_unpickleable_invocation(mocker) -> None:
273271
# gen_id will return a random UUID in case of pickle errors
274-
assert gen_id(unpickleable_fn, [], {}) != gen_id(unpickleable_fn, [], {})
272+
some_fn = lambda x: x
273+
unpicklable_arg = [1]
274+
assert gen_id(some_fn, unpicklable_arg, {}) != gen_id(some_fn, unpicklable_arg, {})
275+
"""

zetta_utils/mazepa/id_generation.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import uuid
55
from typing import Callable, Optional
66

7+
from sympy import im
8+
79
import cloudpickle
810
import xxhash
911
from coolname import generate_slug
@@ -40,6 +42,7 @@ def generate_invocation_id(
4042
args: Optional[list] = None,
4143
kwargs: Optional[dict] = None,
4244
prefix: Optional[str] = None,
45+
debug: Optional[bool] = False,
4346
) -> str:
4447
"""Generate a unique and deterministic ID for a function invocation.
4548
The ID is generated using xxhash and cloudpickle to hash the function and its arguments.
@@ -51,10 +54,25 @@ def generate_invocation_id(
5154
:return: A unique, yet deterministic string that identifies (fn, args, kwargs) in
5255
the current Python environment.
5356
"""
57+
# import dill
58+
import pickletools
59+
#return cloudpickle.dumps((fn, args, kwargs), protocol=dill.DEFAULT_PROTOCOL)s
60+
if debug:
61+
pickletools.dis(pickletools.optimize(cloudpickle.dumps((fn, args, kwargs))))
62+
63+
return str(cloudpickle.dumps((fn, args, kwargs)))
64+
#return cloudpickle.dumps((fn, args, kwargs), protocol=dill.DEFAULT_PROTOCOL)s
5465
x = xxhash.xxh128()
5566
try:
5667
x.update(cloudpickle.dumps((fn, args, kwargs)))
57-
except Exception as e: # pylint: disable=broad-exception-caught
68+
#x.update(dill.dumps(
69+
#(fn, args, kwargs),
70+
#protocol=dill.DEFAULT_PROTOCOL,
71+
#byref=False,
72+
#recurse=True,
73+
#fmode=dill.FILE_FMODE,
74+
#))
75+
except Exception as e: # pylint: disable=broad-exception-caught
5876
logger.warning(f"Failed to pickle {fn} with args {args} and kwargs {kwargs}: {e}")
5977
x.update(str(uuid.uuid4()))
6078

0 commit comments

Comments
 (0)