deltakit.explorer.types.DataString#

class deltakit.explorer.types.DataString(data: bytes | str = b'')#

Bases: object

Data string is a normal string which encodes arbitrary binary data (e.g. Stim circuit file, or measurements data). These strings may be used instead of file names in any calls to QEC Explorer client. The server recognises these strings by detecting a prefix, and treats them as data.

DataString class provides methods to generate such string from files, strings and byte strings, as well as methods to parse them when the server responds with a data string.

To generate a data string from a file:

dstring_object = DataString.from_file(path_to_file)
dstring = str(dstring_object)  # generate a data string
len(dstring_object.data)  # raw data is stored in `DataString.data` field

To parse a data string:

dstring_object = DataString.from_data_string(datastring)

To generate a data string from a variable:

bytes_content = b"1,1,0,1,0\n1,1,1,0,1\n"
csv_measurements = DataString(bytes_content)
b8_measurements = qec_client.convert_format(
    input_file=csv_measurements,
    input_format="csv",
    output_format="b8",
)
b8_measurements.to_file("data.b8")

To convert the content of a DataString object to a string:

string = data_string.to_string()

Data strings result in additional processing on client and server side, they introduce redundancy in data, and they also increase network traffic between client and server nodes.

Construct an object from the data.

Parameters:

data (bytes | str, optional) – bytes data to be encode, or a string, interpreted as UTF-8. Defaults to b””.

Methods#

DataString.from_data_string

Parse the data string into a bytes object.

DataString.from_file

Create a data string from a file name.

DataString.is_data_string

Check that the string corresponds to a data string syntax.

DataString.to_file

Dump data to a file.

DataString.to_string

Converts DataString object to string.