From 9439a25f9464a5cae247e7177eb7c11377a4c016 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20H=C3=B6nig?= <jan.hoenig@fau.de>
Date: Wed, 4 May 2022 09:55:23 +0200
Subject: [PATCH] Made CreateKernelConfig pickable

---
 pystencils/config.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/pystencils/config.py b/pystencils/config.py
index e5f223925..79de166c9 100644
--- a/pystencils/config.py
+++ b/pystencils/config.py
@@ -125,6 +125,14 @@ class CreateKernelConfig:
     periodicity kernel, that access the field outside the iteration bounds. Use with care!
     """
 
+    class DataTypeFactory:
+        """Because of pickle, we need to have a nested class, instead of a lambda in __post_init__"""
+        def __init__(self, dt):
+            self.dt = dt
+
+        def __call__(self):
+            return BasicType(self.dt)
+
     def __post_init__(self):
         # ----  Legacy parameters
         # TODO Sane defaults: Check for abmigous types like "float", python float, which are dangerous for users
@@ -145,8 +153,9 @@ class CreateKernelConfig:
         #  Normalise data types
         if not isinstance(self.data_type, dict):
             dt = copy(self.data_type)  # The copy is necessary because BasicType has sympy shinanigans
-            self.data_type = defaultdict(lambda: BasicType(dt))
+            self.data_type = defaultdict(self.DataTypeFactory(dt))
         if not isinstance(self.default_number_float, BasicType):
             self.default_number_float = BasicType(self.default_number_float)
         if not isinstance(self.default_number_int, BasicType):
             self.default_number_int = BasicType(self.default_number_int)
+
-- 
GitLab