def _to_dict(self): def class_to_dict(cls): return obj_to_dict(self, _build=False, _name=cls.__name__, _module=cls.__module__) args = list(self.args) if isinstance(self.cls, Parametrized): cls_dict = self.cls._to_dict() elif (hasattr(args[0], self.cls.__name__) and inspect.isfunction(self.cls)): # Check for parametrized methods if inspect.isclass(self.args[0]): # classmethod cls_dict = obj_to_dict(self, _build=False, _name=self.cls.__name__, _module=self.args[0].__module__, _submodule=self.args[0].__name__) args[0] = class_to_dict(self.args[0]) else: raise NotImplementedError("Instance or static method " "serialization is not supported.") else: cls_dict = class_to_dict(self.cls) return obj_to_dict(self, cls_dict, *args, **self.kwargs)
def default(self, o): if hasattr(o, "_to_dict"): return o._to_dict() elif type(o) == type: return obj_to_dict(o, _build=False, _name=o.__name__) elif isinstance(o, np.ndarray): return obj_to_dict(o, o.tolist(), _name="array") elif isinstance(o, set): return obj_to_dict(o, list(o)) else: return JSONEncoder.default(self, o)
def _to_dict(self): d = obj_to_dict(self, *self._calls[0].args, **self._calls[0].kwargs) d["__version__"] = pulser.__version__ d["calls"] = self._calls[1:] d["vars"] = self._variables d["to_build_calls"] = self._to_build_calls return d
def _to_dict(self): return obj_to_dict(self, self._duration, self._area)
def _to_dict(self): return obj_to_dict(self, self._duration, self._start, self._stop)
def _to_dict(self): return obj_to_dict(self, self._duration, self._value)
def _to_dict(self): return obj_to_dict(self, self._samples)
def _to_dict(self): return obj_to_dict(self, *self._waveforms)
def _to_dict(self): return obj_to_dict(self, _build=False, _module="pulser.devices", _name=self.name)
def _to_dict(self): qs = dict(zip(self._ids, map(np.ndarray.tolist, self._coords))) return obj_to_dict(self, qs)
def _to_dict(self): return obj_to_dict(self, self.amplitude, self.detuning, self.phase, post_phase_shift=self.post_phase_shift)
def class_to_dict(cls): return obj_to_dict(self, _build=False, _name=cls.__name__, _module=cls.__module__)