Decoders

mUQSA Decoders play an analogical role to the encoders, but on the other site of the evaluation. A decoder is a function that transforms the output data from a simulation code or model from its native format into the mUQSA format required in the remaining part of the mUQSA workflow, i.e., analysis and visualization. For example, if a simulation code outputs data in a specific format, such as a binary file or a specific data structure, the decoder function is used to get the data related to specific Quantities of Interest (QoIs) from the output, and put it into the common mUQSA data structure.

mUQSA provides a few types of built-in decoders inherited from EasyVVUQ library that can be used to decode common types of data formats. Custom decoders can be created for other use cases as well.

Built-in Decoders

CSV Decoder

CSV Decoder allows decoding data from csv data files. To run, CSV Decoder requires information about the name of the output csv file generated by the simulation code and a list of column names from which the data should be decoded and put into the UQSA’s structures.

Let’s assume the following CSV output from the simulation:

c1,c2,c3
0.1,10,20
0.2,11,21

If we are interested in values from c1 and c3, then we may use CSVDecoder and pass the following list of colum names as its parameter:

c1, c3

The selected c1 and c3 columns will be automatically extracted and placed appropriately in the mUQSA’s data structures.

JSON Decoder

JSON Decoder allows decoding data stored in JSON files. It requires the name of the JSON file and a list of JSON element names to decode as inputs. It is possible to request for decoding on of top-level json elements or any child element. In the first case, the element of a list can be simply a name; in the second the element of a list should be a next list containing the names of all subsequent JSON elements: starting from the root element name and ending with the name of the target, the most nested element.

Consider the following JSON file:

{
  "e1": {
    "e11": {
      "v111": 1.0,
      "v112": 2.0
    },
    "v12": true
  },
  "v2": "Some string"
}

Assuming we are interested in values of v112 and v2, then our list of elements to decode should look as follows:

[e1, e11, v112], v2

YAML Decoder

YAML Decoder provides the same features as JSON Decoder, but for YAML files. The input to the decoder is a YAML file and a list of elements whose values should be decoded. Similarly to JSON Decoder, the list can contain the names of top-level YAML elements, or a list-based accessors to a nested elements.

Let’s see how the above example will look in YAML file:

"e1":
  "e11":
    "v111": 1.0
    "v112": 2.0
  "v12": true
"v2": "Some string"

Again, assuming that we are interested in v112 and v2, the list with specification of elements to decode will have very the same form as above:

[e1, e11, v112], v2

Custom Decoders

mUQSA supports the creation of custom decoders whenever the functionality of the built-in ones is not sufficient. However, the first question we should answer before moving to the implementation of a custom decoder is if we really need to do so? Maybe better would be just to change the format of output data our application produces, or it would be easier to create some postprocess script that automatically translates the output to CSV or JSON that built-in decoders can handle.

If you decide on the implementation of your own decoder, you need to implement a class with the following scheme:

class CustomDecoder:
    def __init__(self, target_filename=None, output_columns=None):
        pass

    def parse_sim_output(self, run_info={}):
        return {}

The parse_sim_output method takes run_info as a parameter. When invoked internally by EasyVVUQ library, it contains a bunch of data from which the run_dir that contains an absolute path to a run directory, may be the most useful. The method should return a single level deep dictionary where keys are QoI variable names and values are either scalar values or lists if they are vectors:

{"a" : 0.01, "b" : [1, 2, 3], "c" : "..."}

For more information and reference, please take a look at the existing EasyVVUQ decoders.