TBTK
|
Need a break? Support the development by playing Polarity Puzzles |
TBTK provides a number of methods for reading and writing to external memory. We describe these methods here.
The FileParser can generate a ParameterSet by parsing a file formated as follows.
Assume the file is called "ParameterFile". It is then possible to parse it and extract the values using
Many classes implement the Serializable interface. This means that they can be converted into text strings that can then be converted back into objects.
For example, the following code first serializes a Model and then recreates a copy of it from the resulting serialization string.
The parameter Serializable::Mode::JSON indicates that the serialization should be done to and from JSON. Currently, this is the only widely supported serialization format in TBTK.
The power of serialization is that a string can be stored or sent anywhere. The Resource class is meant to simplify this task. For example, the serialization created above can be saved to a file called Model.json using
The Model can then be read in and reconstructed in a different program using
The Resource can also download data from a URL. For example, the following code creates a Model from a file downloaded from www.second-quantization.com.
To be able to use the Resource class, cURL must be installed when TBTK is compiled.
The Exporter can be used to export Arrays and Properties to plain text files. The purpose is to make it easy to transfer data to, for example, Python or MATLAB for post-processing. An Array or Property on the None or Ranges format can be exported as follows.
If the Property is on the Custom format, an additional pattern Index is needed to determine the set of Indices to export the Property for. For example, it is possible to export a Property with the index structure {x, y, z} for all Indices of the form {x, 5, z} as follows.
By default, the Exporter exports data using row major order. Some other languages, e.g. MATLAB and Fortran, uses column major order and it is, therefore, possible to change the output format. This is done through the following command.
The following code can be used to import the data into Python
Here it is assumed that the data is three-dimensional with size SIZE_X, SIZE_Y, and SIZE_Z, and that the data has been exported on the row major order format (default).
Similarly, the following code can be used to import the data into MATLAB
Here it is assumed that the data is three-dimensional with size SIZE_X, SIZE_Y, and SIZE_Z, and that the data has been exported on the column major order format.