From bbcefe160a6c431afc94d43c259df56085dfc39a Mon Sep 17 00:00:00 2001 From: Stephan Seitz <stephan.seitz@fau.de> Date: Tue, 14 Mar 2023 22:58:25 +0100 Subject: [PATCH] fix: MappingProxyType is not a constant and should therefor use default_factory Fixes execution on Python 3.11 Prevents the following error: ``` ImportError while loading conftest '/home/stephan/projects/pystencils/conftest.py'. conftest.py:14: in <module> from pystencils.cpu import cpujit pystencils/__init__.py:10: in <module> from .config import CreateKernelConfig pystencils/config.py:19: in <module> @dataclass /usr/lib/python3.11/dataclasses.py:1220: in dataclass return wrap(cls) /usr/lib/python3.11/dataclasses.py:1210: in wrap return _process_class(cls, init, repr, eq, order, unsafe_hash, /usr/lib/python3.11/dataclasses.py:958: in _process_class cls_fields.append(_get_field(cls, name, type, kw_only)) /usr/lib/python3.11/dataclasses.py:815: in _get_field raise ValueError(f'mutable default {type(f.default)} for field ' E ValueError: mutable default <class 'mappingproxy'> for field gpu_indexing_params is not allowed: use default_factory ``` --- pystencils/config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pystencils/config.py b/pystencils/config.py index 7c2be7a66..23570d625 100644 --- a/pystencils/config.py +++ b/pystencils/config.py @@ -82,7 +82,7 @@ class CreateKernelConfig: """ Either 'block' or 'line' , or custom indexing class, see `pystencils.gpucuda.AbstractIndexing` """ - gpu_indexing_params: MappingProxyType = field(default=MappingProxyType({})) + gpu_indexing_params: MappingProxyType = field(default_factory=lambda: MappingProxyType({})) """ Dict with indexing parameters (constructor parameters of indexing class) e.g. for 'block' one can specify '{'block_size': (20, 20, 10) }'. @@ -121,12 +121,12 @@ class CreateKernelConfig: allow_double_writes: bool = False """ If True, don't check if every field is only written at a single location. This is required - for example for kernels that are compiled with loop step sizes > 1, that handle multiple + for example for kernels that are compiled with loop step sizes > 1, that handle multiple cells at once. Use with care! """ skip_independence_check: bool = False """ - Don't check that loop iterations are independent. This is needed e.g. for + Don't check that loop iterations are independent. This is needed e.g. for periodicity kernel, that access the field outside the iteration bounds. Use with care! """ -- GitLab