示例#1
0
    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)
示例#2
0
 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)
示例#3
0
 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
示例#4
0
 def _to_dict(self):
     return obj_to_dict(self, self._duration, self._area)
示例#5
0
 def _to_dict(self):
     return obj_to_dict(self, self._duration, self._start, self._stop)
示例#6
0
 def _to_dict(self):
     return obj_to_dict(self, self._duration, self._value)
示例#7
0
 def _to_dict(self):
     return obj_to_dict(self, self._samples)
示例#8
0
 def _to_dict(self):
     return obj_to_dict(self, *self._waveforms)
示例#9
0
 def _to_dict(self):
     return obj_to_dict(self, _build=False, _module="pulser.devices",
                        _name=self.name)
示例#10
0
 def _to_dict(self):
     qs = dict(zip(self._ids, map(np.ndarray.tolist, self._coords)))
     return obj_to_dict(self, qs)
示例#11
0
文件: pulse.py 项目: sphkthnch/Pulser
 def _to_dict(self):
     return obj_to_dict(self,
                        self.amplitude,
                        self.detuning,
                        self.phase,
                        post_phase_shift=self.post_phase_shift)
示例#12
0
 def class_to_dict(cls):
     return obj_to_dict(self,
                        _build=False,
                        _name=cls.__name__,
                        _module=cls.__module__)