def default(self, o: Any) -> dict[str, Any]: """Handles JSON encoding of objects not supported by default.""" if hasattr(o, "_to_dict"): return cast(dict, 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 cast(dict, JSONEncoder.default(self, o))
def _to_dict(self) -> dict[str, Any]: return obj_to_dict( self, self.amplitude, self.detuning, self.phase, post_phase_shift=self.post_phase_shift, )
def _to_dict(self) -> dict[str, Any]: # Allows for serialization of subclasses without a special _to_dict() return obj_to_dict( self, self.trap_coordinates, _module=__name__, _name="RegisterLayout", )
def _to_dict(self) -> dict[str, Any]: def class_to_dict(cls: Callable) -> dict[str, Any]: module = "numpy" if isinstance(cls, np.ufunc) else cls.__module__ return obj_to_dict( self, _build=False, _name=cls.__name__, _module=module ) args = list(self.args) if isinstance(self.cls, Parametrized): raise ValueError( "Serialization of calls to parametrized objects is not " "supported." ) 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 _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, self._layout, *self._qubit_ids)
def _to_dict(self) -> dict[str, Any]: d = obj_to_dict(self, _build=False) d.update(dataclasses.asdict(self)) return d
def _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, self._rows, self._columns, self._spacing)
def _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, *self._waveforms)
def _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, self._duration, self._area, self._beta)
def _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, self.number_of_traps, self._spacing)
def _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, self._duration, self._values, **self._kwargs)
def _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, self._duration, self._start, self._stop)
def _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, self._samples)
def class_to_dict(cls: Callable) -> dict[str, Any]: module = "numpy" if isinstance(cls, np.ufunc) else cls.__module__ return obj_to_dict( self, _build=False, _name=cls.__name__, _module=module )
def _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, self.var, self.key, _module="operator", _name="getitem")
def _to_dict(self) -> dict[str, Any]: qs = dict(zip(self._ids, map(np.ndarray.tolist, self._coords))) if self._layout_info is not None: return obj_to_dict(self, qs, **(self._layout_info._asdict())) return obj_to_dict(self, qs)
def _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, _build=False, _module="pulser.devices", _name=self.name)