def dict( simulator: Simulator, signal_processors: list = None, params: Parameters = None, with_units: bool = True, ): """Export the Simulator, list of SignalProcessor, and lmfit Parameters objects to a python dictionary. Args: sim: Simulator object. signal_processors: A list of PostSimulator objects corresponding to the methods in the Simulator object. Default is None. params: lmfit Parameters object. Default is None. bool with_units: If true, physical quantities are represented as string with units. The default is True. Return: Python dictionary """ py_dict = simulator.json(units=with_units) if signal_processors is not None: py_dict["signal_processors"] = [ item.json() for item in signal_processors ] py_dict["params"] = None if params is None else params.dumps() return py_dict
def simulate_spectrum(): """Create a new mrsimulator file from params. The new file then undergoes a fresh simulation""" print("The Simulate Spectrum button has been clicked") mrsim_data = ctx.states["local-mrsim-data.data"] params_data = ctx.states["params-data.data"] if mrsim_data is None: raise PreventUpdate if len(mrsim_data["methods"]) == 0 or len(mrsim_data["spin_systems"]) == 0: raise PreventUpdate sim, processor, saved_params = mrsim.parse(mrsim_data) params = Parameters().loads(params_data) sf.update_mrsim_obj_from_params(params, sim, processor) new_mrsim_data = mrsim.dict(sim, processor, saved_params) new_mrsim_data["params"] = params.dumps() out = { "alert": ["", False], "mrsim": [new_mrsim_data, no_update], "children": [no_update, no_update, no_update], "mrsim_config": [no_update, no_update, no_update, no_update], "processor": [no_update], } return sim_utils.expand_output(out)
def test_dumps_loads_parameters(self): # test that we can dumps() and then loads() a Parameters pars = Parameters() pars.add('x', value=1.0) pars.add('y', value=2.0) pars['x'].expr = 'y / 2.0' dumps = pars.dumps() newpars = Parameters().loads(dumps) newpars['y'].value = 100.0 assert_(isclose(newpars['x'].value, 50.0))