def load(cls, filename: str, parse_units=True): """Load the :class:`~mrsimulator.Simulator` object from a JSON file by parsing. Args: bool parse_units: If true, parse the attribute values from the serialized file for physical quantities, expressed as a string with a value and a unit. str filename: The filename of a JSON serialized mrsimulator file. Returns: A :class:`~mrsimulator.Simulator` object. Example ------- >>> sim_1 = sim.load('filename') # doctest: +SKIP .. seealso:: :ref:`load_spin_systems` """ contents = import_json(filename) if not parse_units: return Simulator(**contents) return Simulator.parse_dict_with_units(contents)
def load_methods(self, filename: str): """Load a list of methods from the given JSON serialized file. Args: str filename: A local or remote address to a JSON serialized file. Example ------- >>> sim.load_methods(filename) # doctest:+SKIP """ contents = import_json(filename) self.methods = [Method.parse_dict_with_units(obj) for obj in contents]
def load(filename: str, parse_units: bool = True): """Load Simulator object and list of SignalProcessor objects from a JSON searalized file of a :py:class:`~mrsimulator.Mrsimulator` object. Args: str filename: The location to the .mrsim file. bool parse_units: If true, parse the dictionary for units. The default is True. Return: Ordered List: Simulator, List[SignalProcessor]. """ val = import_json(filename) return parse(val, parse_units)
def load(filename: str, parse_units: bool = True): """Load Simulator, list of SignalProcessor and optionally lmfit Parameters objects from the .mrsim file. Args: str filename: The location to the .mrsim file. bool parse_units: If true, parse the dictionary for units. The default is True. Return: Ordered List: Simulator, List[SignalProcessor], Parameters. """ val = import_json(filename) return parse(val, parse_units)
def load(cls, filename: str, with_units: bool = True): """Load the :py:class: `~mrsimulator.Mrsimulator` object from a JSON file by parsing a file from a given path Args: bool parse_units: If true, parse the attribute values from the serialized file for physical quantities, expressed as a string with a value and a unit. str filename: The filename of a JSON serialized Mrsimulator object file. Example ------- >>> mrsim = Mrsimulator.load("filename") # doctest: +SKIP """ contents = import_json(filename) return Mrsimulator.parse(contents, with_units)
def load_spin_systems(self, filename: str): """Load a list of spin systems from the given JSON serialized file. See an `example <https://raw.githubusercontent.com/deepanshs/mrsimulator-examples/ master/spin_systems_v0.3.json>`_ of a JSON serialized file. For details, refer to the :ref:`load_spin_systems` section of this documentation. Args: str filename: A local or remote address to a JSON serialized file. Example ------- >>> sim.load_spin_systems(filename) # doctest:+SKIP """ contents = import_json(filename) self.spin_systems = [SpinSystem.parse_dict_with_units(obj) for obj in contents]
def mrsim_to_v0_7(filename: str, overwrite: bool = False): """Convert an old mrsim file where Simulator object keywords existed at the root level along with other seralized attributes to a structure where each object exists under its own keyword. New file will be saved as <given_name>_new.mrsim Args: str filename: path to searalized file overwrite: Will overwrite file if true, otherwise just returns dict Returns: dict: Dictionary of newly seralized Mrsimulator object """ py_dict = import_json(filename) py_dict["simulator"] = {} sim_keywords = { "spin_systems", "methods", "config", "name", "label", "description", "indexes", } # Create Simulator dictionary for key in set(py_dict.keys()).intersection(sim_keywords): py_dict["simulator"][key] = py_dict.pop(key) # Remove all other unknown keywords bad_keys = set(py_dict.keys()) - set(Mrsimulator().dict().keys()) for key in bad_keys: py_dict.pop(key) obj = Mrsimulator.parse_dict_with_units(py_dict) if overwrite: obj.save(filename=filename) return py_dict