2.12.2.1. prismatique.worker.cpu.Params
- class Params(enable_workers=True, num_worker_threads=12, batch_size=1, early_stop_count=100, skip_validation_and_conversion=False)[source]
Bases:
PreSerializableAndUpdatableThe simulation parameters related to CPU workers.
- Parameters:
- enable_workersbool, optional
If set to
True, then the simulation will also make use of CPU workers, in addition to GPU workers (if available).- num_worker_threadsint, optional
Let
num_available_worker_threadsbe the number of CPU worker threads available for the simulation. Ifenable_workershas been set toTrue, thenmax(num_available_worker_threads, num_worker_threads)determines the number of CPU worker threads that are to be used in the simulation. Ifenable_workershas been set toFalse, then the parameternum_worker_threadsis ignored upon configuring the simulation. See the documentation for the classprismatique.worker.Paramsfor a discussion on how the number of CPU worker threads affects performance.- batch_sizeint, optional
The calculation of the transmission of a single probe or plane wave through the entire sample (i.e. from the incident surface to the exit surface) involves a series of fast-Fourier transform (FFT) operations. FFTs are calculated using a divide-and-conquer algorithm that recursively breaks down a discrete Fourier transform (DFT) into smaller DFTs and performs multiplications involving complex roots of unity called twiddle factors. Thus, a given FFT in this scheme is calculated in multiple steps. The libraries used in
prismaticthat implement FFTs support batch FFTs, whereby multiple Fourier transforms of the same size can be computed simultaneously. By simultaneously, we mean that step \(i+1\) of a given FFT in a given batch cannot be executed until step \(i\) has been executed for all FFTs in said batch. This order of operations allows for reuse of intermediate twiddle factors, resulting in a faster overall computation than performing individual transforms one-by-one at the expense of requiring a larger block of memory to store the multiple arrays. We can therefore use this batch FFT method to calculate the transmission of a batch of probes or plane waves simultaneously in the same sense as that articulated above.If
enable_workershas been set toTrue, thenbatch_sizespecifies the number of probes or plane waves to transmit simultaneously per CPU worker. Ifenable_workershas been set toFalse, then the parameterbatch_sizeis ignored upon configuring the simulation.- early_stop_countint, optional
Assuming that GPUs have been enabled to do work in the simulation, then the work dispatcher will cease providing work to the CPU workers
early_stop_countjobs from the end. This is to prevent the program waiting for CPU workers to complete that are slower than the enabled GPU workers. What qualifies as a job in this context is unclear from the documentation of theprismaticlibrary. Presumably, a typical job could be a batch FFT operation, or a series of element-wise multiplication operations. In any case, the user could try experimenting with this parameter to see if it yields appreciable performance gains. If no GPUs have been enabled to do work in the simulation, then the parameterearly_stop_countis ignored upon configuring the simulation.- skip_validation_and_conversionbool, optional
Let
validation_and_conversion_funcsandcore_attrsdenote the attributesvalidation_and_conversion_funcsandcore_attrsrespectively, both of which being dict objects.Let
params_to_be_mapped_to_core_attrsdenote the dict representation of the constructor parameters excluding the parameterskip_validation_and_conversion, where each dict keykeyis a different constructor parameter name, excluding the name"skip_validation_and_conversion", andparams_to_be_mapped_to_core_attrs[key]would yield the value of the constructor parameter with the name given bykey.If
skip_validation_and_conversionis set toFalse, then for each keykeyinparams_to_be_mapped_to_core_attrs,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (params_to_be_mapped_to_core_attrs).Otherwise, if
skip_validation_and_conversionis set toTrue, thencore_attrsis set toparams_to_be_mapped_to_core_attrs.copy(). This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values ofparams_to_be_mapped_to_core_attrs, as it is guaranteed that no copies or conversions are made in this case.
- Attributes:
core_attrsdict: The “core attributes”.
de_pre_serialization_funcsdict: The de-pre-serialization functions.
pre_serialization_funcsdict: The pre-serialization functions.
validation_and_conversion_funcsdict: The validation and conversion functions.
Methods
de_pre_serialize([serializable_rep, ...])Construct an instance from a serializable representation.
dump([filename, overwrite])Serialize instance and save the result in a JSON file.
dumps()Serialize instance.
get_core_attrs([deep_copy])Return the core attributes.
Return the de-pre-serialization functions.
Return the pre-serialization functions.
Return the validation and conversion functions.
load([filename, skip_validation_and_conversion])Construct an instance from a serialized representation that is stored in a JSON file.
loads([serialized_rep, ...])Construct an instance from a serialized representation.
Pre-serialize instance.
update([new_core_attr_subset_candidate, ...])Update a subset of the core attributes.
Methods
Construct an instance from a serializable representation.
Serialize instance and save the result in a JSON file.
Serialize instance.
Return the core attributes.
Return the de-pre-serialization functions.
Return the pre-serialization functions.
Return the validation and conversion functions.
Construct an instance from a serialized representation that is stored in a JSON file.
Construct an instance from a serialized representation.
Pre-serialize instance.
Update a subset of the core attributes.
Attributes
dict: The "core attributes".
dict: The de-pre-serialization functions.
dict: The pre-serialization functions.
dict: The validation and conversion functions.
- property core_attrs
dict: The “core attributes”.
The keys of
core_attrsare the same as the attributevalidation_and_conversion_funcs, which is also a dict object.Note that
core_attrsshould be considered read-only.
- property de_pre_serialization_funcs
dict: The de-pre-serialization functions.
de_pre_serialization_funcshas the same keys as the attributevalidation_and_conversion_funcs, which is also a dict object.Let
validation_and_conversion_funcsandpre_serialization_funcsdenote the attributesvalidation_and_conversion_funcspre_serialization_funcsrespectively, the last of which being a dict object as well.Let
core_attrs_candidate_1be any dict object that has the same keys asvalidation_and_conversion_funcs, where for each dict keykeyincore_attrs_candidate_1,validation_and_conversion_funcs[key](core_attrs_candidate_1)does not raise an exception.Let
serializable_repbe a dict object that has the same keys ascore_attrs_candidate_1, where for each dict keykeyincore_attrs_candidate_1,serializable_rep[key]is set topre_serialization_funcs[key](core_attrs_candidate_1[key]).The items of
de_pre_serialization_funcsare expected to be set to callable objects that would lead tode_pre_serialization_funcs[key](serializable_rep[key])not raising an exception for each dict keykeyinserializable_rep.Let
core_attrs_candidate_2be a dict object that has the same keys asserializable_rep, where for each dict keykeyinvalidation_and_conversion_funcs,core_attrs_candidate_2[key]is set tode_pre_serialization_funcs[key](serializable_rep[key]).The items of
de_pre_serialization_funcsare also expected to be set to callable objects that would lead tovalidation_and_conversion_funcs[key](core_attrs_candidate_2)not raising an exception for each dict keykeyincore_attrs_candidate_2.Note that
de_pre_serialization_funcsshould be considered read-only.
- classmethod de_pre_serialize(serializable_rep={}, skip_validation_and_conversion=False)
Construct an instance from a serializable representation.
- Parameters:
- serializable_repdict, optional
A dict object that has the same keys as the attribute
validation_and_conversion_funcs, which is also a dict object.Let
validation_and_conversion_funcsandde_pre_serialization_funcsdenote the attributesvalidation_and_conversion_funcsde_pre_serialization_funcsrespectively, the last of which being a dict object as well.The items of
serializable_repare expected to be objects that would lead tode_pre_serialization_funcs[key](serializable_rep[key])not raising an exception for each dict keykeyinserializable_rep.Let
core_attrs_candidatebe a dict object that has the same keys asserializable_rep, where for each dict keykeyinserializable_rep,core_attrs_candidate[key]is set to de_pre_serialization_funcs[key](serializable_rep[key])``.The items of
serializable_repare also expected to be set to objects that would lead tovalidation_and_conversion_funcs[key](core_attrs_candidate)not raising an exception for each dict keykeyinserializable_rep.- skip_validation_and_conversionbool, optional
Let
core_attrsdenote the attributecore_attrs, which is a dict object.If
skip_validation_and_conversionis set toFalse, then for each keykeyinserializable_rep,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (core_attrs_candidate), withvalidation_and_conversion_funcsandcore_attrs_candidate_1being introduced in the above description ofserializable_rep.Otherwise, if
skip_validation_and_conversionis set toTrue, thencore_attrsis set tocore_attrs_candidate.copy(). This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values ofcore_attrs_candidate, as it is guaranteed that no copies or conversions are made in this case.
- Returns:
- instance_of_current_clsCurrent class
An instance constructed from the serializable representation
serializable_rep.
- dump(filename='serialized_rep_of_fancytype.json', overwrite=False)
Serialize instance and save the result in a JSON file.
- Parameters:
- filenamestr, optional
The relative or absolute path to the JSON file in which to store the serialized representation of an instance.
- overwritebool, optional
If
overwriteis set toFalseand a file exists at the pathfilename, then the serialized instance is not written to that file and an exception is raised. Otherwise, the serialized instance will be written to that file barring no other issues occur.
- Returns:
- dumps()
Serialize instance.
- Returns:
- serialized_repdict
A serialized representation of an instance.
- get_core_attrs(deep_copy=True)
Return the core attributes.
- Parameters:
- deep_copybool, optional
Let
core_attrsdenote the attributecore_attrs, which is a dict object.If
deep_copyis set toTrue, then a deep copy ofcore_attrsis returned. Otherwise, a shallow copy ofcore_attrsis returned.
- Returns:
- core_attrsdict
The attribute
core_attrs.
- classmethod get_de_pre_serialization_funcs()[source]
Return the de-pre-serialization functions.
- Returns:
- de_pre_serialization_funcsdict
The attribute
de_pre_serialization_funcs.
- classmethod get_pre_serialization_funcs()[source]
Return the pre-serialization functions.
- Returns:
- pre_serialization_funcsdict
The attribute
pre_serialization_funcs.
- classmethod get_validation_and_conversion_funcs()[source]
Return the validation and conversion functions.
- Returns:
- validation_and_conversion_funcsdict
The attribute
validation_and_conversion_funcs.
- classmethod load(filename='serialized_rep_of_fancytype.json', skip_validation_and_conversion=False)
Construct an instance from a serialized representation that is stored in a JSON file.
Users can save serialized representations to JSON files using the method
fancytypes.PreSerializable.dump().- Parameters:
- filenamestr, optional
The relative or absolute path to the JSON file that is storing the serialized representation of an instance.
filenameis expected to be such thatjson.load(open(filename, "r"))does not raise an exception.Let
serializable_rep=json.load(open(filename, "r")).Let
validation_and_conversion_funcsandde_pre_serialization_funcsdenote the attributesvalidation_and_conversion_funcsde_pre_serialization_funcsrespectively, both of which being dict objects as well.filenameis also expected to be such thatde_pre_serialization_funcs[key](serializable_rep[key])does not raise an exception for each dict keykeyinde_pre_serialization_funcs.Let
core_attrs_candidatebe a dict object that has the same keys asde_pre_serialization_funcs, where for each dict keykeyinserializable_rep,core_attrs_candidate[key]is set to de_pre_serialization_funcs[key](serializable_rep[key])``.filenameis also expected to be such thatvalidation_and_conversion_funcs[key](core_attrs_candidate)does not raise an exception for each dict keykeyinserializable_rep.- skip_validation_and_conversionbool, optional
Let
core_attrsdenote the attributecore_attrs, which is a dict object.Let
core_attrs_candidatebe as defined in the above description offilename.If
skip_validation_and_conversionis set toFalse, then for each keykeyincore_attrs_candidate,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (core_attrs_candidate), , withvalidation_and_conversion_funcsandcore_attrs_candidatebeing introduced in the above description offilename.Otherwise, if
skip_validation_and_conversionis set toTrue, thencore_attrsis set tocore_attrs_candidate.copy(). This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values ofcore_attrs_candidate, as it is guaranteed that no copies or conversions are made in this case.
- Returns:
- instance_of_current_clsCurrent class
An instance constructed from the serialized representation stored in the JSON file.
- classmethod loads(serialized_rep='{}', skip_validation_and_conversion=False)
Construct an instance from a serialized representation.
Users can generate serialized representations using the method
dumps().- Parameters:
- serialized_repstr | bytes | bytearray, optional
The serialized representation.
serialized_repis expected to be such thatjson.loads(serialized_rep)does not raise an exception.Let
serializable_rep=json.loads(serialized_rep).Let
validation_and_conversion_funcsandde_pre_serialization_funcsdenote the attributesvalidation_and_conversion_funcsde_pre_serialization_funcsrespectively, both of which being dict objects as well.serialized_repis also expected to be such thatde_pre_serialization_funcs[key](serializable_rep[key])does not raise an exception for each dict keykeyinde_pre_serialization_funcs.Let
core_attrs_candidatebe a dict object that has the same keys asserializable_rep, where for each dict keykeyinde_pre_serialization_funcs,core_attrs_candidate[key]is set to de_pre_serialization_funcs[key](serializable_rep[key])``.serialized_repis also expected to be such thatvalidation_and_conversion_funcs[key](core_attrs_candidate)does not raise an exception for each dict keykeyinserializable_rep.- skip_validation_and_conversionbool, optional
Let
core_attrsdenote the attributecore_attrs, which is a dict object.If
skip_validation_and_conversionis set toFalse, then for each keykeyincore_attrs_candidate,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (core_attrs_candidate), withvalidation_and_conversion_funcsandcore_attrs_candidate_1being introduced in the above description ofserialized_rep.Otherwise, if
skip_validation_and_conversionis set toTrue, thencore_attrsis set tocore_attrs_candidate.copy(). This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values ofcore_attrs_candidate, as it is guaranteed that no copies or conversions are made in this case.
- Returns:
- instance_of_current_clsCurrent class
An instance constructed from the serialized representation.
- property pre_serialization_funcs
dict: The pre-serialization functions.
pre_serialization_funcshas the same keys as the attributevalidation_and_conversion_funcs, which is also a dict object.Let
validation_and_conversion_funcsandcore_attrsdenote the attributesvalidation_and_conversion_funcsandcore_attrsrespectively, the last of which being a dict object as well.For each dict key
keyincore_attrs,pre_serialization_funcs[key](core_attrs[key])is expected to yield a serializable object, i.e. it should yield an object that can be passed into the functionjson.dumpswithout raising an exception.Note that
pre_serialization_funcsshould be considered read-only.
- pre_serialize()
Pre-serialize instance.
- Returns:
- serializable_repdict
A serializable representation of an instance.
- update(new_core_attr_subset_candidate={}, skip_validation_and_conversion=False)
Update a subset of the core attributes.
- Parameters:
- new_core_attr_subset_candidatedict, optional
A dict object.
- skip_validation_and_conversionbool, optional
Let
validation_and_conversion_funcsandcore_attrsdenote the attributesvalidation_and_conversion_funcsandcore_attrsrespectively, both of which being dict objects.If
skip_validation_and_conversionis set toFalse, then for each keykeyincore_attrsthat is also innew_core_attr_subset_candidate,core_attrs[key]is set tovalidation_and_conversion_funcs[key] (new_core_attr_subset_candidate).Otherwise, if
skip_validation_and_conversionis set toTrue, then for each keykeyincore_attrsthat is also innew_core_attr_subset_candidate,core_attrs[key]is set tonew_core_attr_subset_candidate[key]. This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values ofnew_core_attr_subset_candidate, as it is guaranteed that no copies or conversions are made in this case.
- property validation_and_conversion_funcs
dict: The validation and conversion functions.
The keys of
validation_and_conversion_funcsare the names of the constructor parameters, excludingskip_validation_and_conversionif it exists as a construction parameter.Let
core_attrsdenote the attributecore_attrs, which is also a dict object.For each dict key
keyincore_attrs,validation_and_conversion_funcs[key](core_attrs)is expected to not raise an exception.Note that
validation_and_conversion_funcsshould be considered read-only.