Sweep definition
Basic description of a sweep in DMT.
Sweeps are the basic element that can be fed into simulators or be retrieved from simulations or measurements. Features:
Clear syntax and definition to create a well described simulation independent of the simulator interface.
- class DMT.core.sweep.Sweep(name: str, sweepdef: ~typing.List[~DMT.core.sweep_def.SweepDef | ~typing.Mapping[str, object]] | None = None, outputdef: ~typing.List[str | ~DMT.core.naming.SpecifierStr] | ~typing.Set[str | ~DMT.core.naming.SpecifierStr] | None = None, othervar: ~typing.Mapping[str, float] | None = None, SweepDefClass: ~typing.Type = <class 'DMT.core.sweep_def.SweepDef'>)[source]
Bases:
objectCreates a sweep.
The following parameters need to be specified in the sweepdef or othervar parameter for every DUT, else an error is raised:
TEMPERATURE: device or simulation temperature
- Parameters:
- name
str Name of the sweep. Prefix for the simulation folder for this sweep. Just for visuals, sometimes ‘VBC0’ is nice.
- sweepdef
List[Dict[str,Unknown] |SweepDef],optional Definition of a sweep. The following keys MUST be specified for each subsweep: ‘var_name’,’sweep_type’. Depending on the sweep type additional keys must be specified:
‘LIN’ : The value for the key ‘value_def’ is an array [start, end, nsteps]. The values are linearly spaced with nsteps from start to end.
‘LOG’ : The value for the key ‘value_def’ is an array [start, end, nsteps]. The values are logarithmically spaced with nsteps from 10^start to 10^end.
‘CON’ : The value for the key ‘value_def’ is an array [val] or single number.
‘SYNC’: The value for the key ‘master’ is a ‘string’ with the value of the key ‘var_name’ of the master sweep. Additionally an ‘offset’ to the master sweep can be specified.
Also note that Sweep() can only sweep potentials, voltages are only swept indirectly. This is a willfull design decision. Ideally the ‘var_name’ is a
SpecifierStr, butget_specifier_from_string()is called on the variable name anyway. So if a unique conversion exists var_name can be a string.If the key ‘sweep_order’ is not explicitly specified, it is given by the sweep definitions position in the list with increasing order. Examples:
sweepdef = [ {'var_name':specifiers.VOLTAGE+'B', 'sweep_order':1, 'sweep_type':'LIN', 'value_def':[0,1,11]}, {'var_name':specifiers.VOLTAGE+'C', 'sweep_order':2, 'sweep_type':'CON', 'value_def':[1]}, {'var_name':specifiers.VOLTAGE+'E', 'sweep_order':3, 'sweep_type':'CON' , 'value_def':[0]} ] sweepdef = [ #this is equivalent to above sweepdef, now 'sweeporder' corresponds to the dict's position in the list. {'var_name':specifiers.VOLTAGE+'B', 'sweep_type':'LIN', 'value_def':[0,1,11]}, {'var_name':specifiers.VOLTAGE+'C', 'sweep_type':'CON', 'value_def':[1]}, {'var_name':specifiers.VOLTAGE+'E', 'sweep_type':'CON', 'value_def':[0]} ] sweepdef = [ {'var_name':specifiers.VOLTAGE+'B', 'sweep_order':1, 'sweep_type':'LIN' , 'value_def':[0,1,11]}, {'var_name':specifiers.VOLTAGE+'C', 'sweep_order':1, 'sweep_type':'SYNC', 'master':specifiers.VOLTAGE+'B', 'offset':0.1} {'var_name':specifiers.VOLTAGE+'E', 'sweep_order':2, 'sweep_type':'CON' , 'value_def':[0]} ]
- outputdef
List[str]orSet[str] ,optional A list of the variables that shall be computed. Example: [specifiers.CURRENT+’C’,specifiers.CURRENT+’B’]
- othervar
Dict[str,float],optional A dict whose ‘key’:’value’ pairs specify variables that do not need to be included in the sweepdef parameter as they should be constants. Example: {
TEMPERATURE:300,’w’:10}- SweepDefClass
Type,optional From this class the sweep def objects are created and the SweepDefClass checks the sweep type. The user can supply subclasses of
SweepDefhere to allow custom sweep types.
- name
- Attributes:
Methods
check_sweep()
Checks the sweep for correctness with regards to its definition and logical consistency. Also takes care of the master - sync logic.
get_hash()
Returns a hash corresponding to a Sweep object.
create_df()
Returns an prepared
DataFramewith all columns from the sweep definitions and output variables. The sweep definition columns are already prefilled.set_values()
Fills all the values inside the sweepdef object list.
get_temperature()
Returns the reference temperature of the sweep to simulate. Mostly used for key generation.
- check_sweep()[source]
Checks a sweep for correctness.
check_sweep() has the following features:
checks the specified sweep type and converts it to a non-misunderstandable format.
corrects the sweep_order
sets offset for SYNC
checks if non-optional variables are specified
corrects the variable names according to DMT format
- create_df() DataFrame[source]
Fill the dataframe according to the sweepdefinition
- Returns:
DMT.core.DataFrameA pandas dataframe object that corresponds to the specified sweep. Values that need to be calculated are filled with numpy.nan .
- get_hash() str[source]
Returns a hash for this sweep.
- Returns:
strMD5 hash that corresponds to this sweep.
- classmethod get_sweep_from_dataframe(data: ~DMT.core.data_frame.DataFrame, temperature: float | None = None, name: str = 'sweep', outputdef: ~typing.List[str] | None = None, othervar: ~typing.Dict[str, float] | None = None, SweepDefClass: ~typing.Type = <class 'DMT.core.sweep_def.SweepDef'>, decimals_potentials: int = 3, **kwargs) Sweep[source]
Create a Sweep from a DataFrame
- Parameters:
- data
DataFrame data to create a Sweep from.
- temperature
float|None,optional Temperature in Kelvin, if not given it must be part of othervar, by default None
- name
str,optional Name of the sweep to create, by default “sweep”
- outputdef
List[str] |None,optional outputdef of the new Sweep, by default None
- othervar
Dict[str,float] |None,optional othervar of the new Sweep, by default None
- SweepDefClass
Type,optional SweepDefClass for the new sweepdefs, by default SweepDef
- decimals_potentials
int,optional Round to x number of decimals for potentials and frequencies, by default 3
- data
- Returns:
SweepCreated sweep from the dataframe
- DMT.core.sweep.get_sweepdef(data: DataFrame, inner_sweep_voltage: SpecifierStr | None = None, outer_sweep_voltage: SpecifierStr | None = None, col_third: SpecifierStr | None = None, decimals_potentials: int = 3) List[Dict][source]
Given a dataframe, one inner sweep_voltage and one outer sweep voltage, this method tries to create a SweepDefinition that can be used to re-simulate the data.
- Parameters:
- data
DataFrame Frame to extract the sweepdefs from
- inner_sweep_voltage
SpecifierStr|None,optional A specifier that determins the inner sweep voltage, by default None
- outer_sweep_voltage
SpecifierStr|None,optional A specifier that determins the inner outer voltage, by default None
- outer_sweep_voltage
SpecifierStr|None,optional A voltage at a third possible contact, that is not swept but may differ from zero.
- decimals_potentials
int,optional Round the potentials to x number of decimals, by default 3
- data
- Returns:
- sweepdef[{}]
A sweep definition that can be used to init a SweepDef.
- Raises:
IOErrorNo forced potentials (or potentials at all) in the columns. Make sure all forced potentials in the columns are SpecifierStr!”
IOErrorThe supplied voltages do not define unambiguous sweep conditions for the data.
NotImplementedErrorEither set both or no sweep specifier for now!
NotImplementedErrorIf both sweep voltages are set to currents