pygsti.io.stdinput

Text-parsing classes and functions to read input files.

Module Contents

Classes

StdInputParser

Encapsulates a text parser for reading GST input files.

Functions

parse_model(filename)

Parse a model file into a Model object.

class pygsti.io.stdinput.StdInputParser

Bases: object

Encapsulates a text parser for reading GST input files.

Create a new standard-input parser object

use_global_parse_cache = 'True'
parse_circuit(s, lookup=None, create_subcircuits=True)

Parse a circuit from a string.

Parameters

sstring

The string to parse.

lookupdict, optional

A dictionary with keys == reflbls and values == tuples of operation labels which can be used for substitutions using the S<reflbl> syntax.

create_subcircuitsbool, optional

Whether to create sub-circuit-labels when parsing string representations or to just expand these into non-subcircuit labels.

Returns

Circuit

parse_circuit_raw(s, lookup=None, create_subcircuits=True)

Parse a circuit’s constituent pieces from a string.

This doesn’t actually create a circuit object, which may be desirable in some scenarios.

Parameters

sstring

The string to parse.

lookupdict, optional

A dictionary with keys == reflbls and values == tuples of operation labels which can be used for substitutions using the S<reflbl> syntax.

create_subcircuitsbool, optional

Whether to create sub-circuit-labels when parsing string representations or to just expand these into non-subcircuit labels.

Returns

label_tuple: tuple

Tuple of operation labels representing the circuit’s layers.

line_labels: tuple or None

A tuple or None giving the parsed line labels (follwing the ‘@’ symbol) of the circuit.

occurrence_id: int or None

The “occurence id” - an integer following a second ‘@’ symbol that identifies a particular copy of this circuit.

compilable_indicestuple or None

A tuple of layer indices (into label_tuple) marking the layers that can be “compiled”, and are not followed by a barrier so they can be compiled with following layers. This is non-None only when there are explicit markers within the circuit string indicating the presence or absence of barriers.

parse_dataline(s, lookup=None, expected_counts=-1, create_subcircuits=True, line_labels=None)

Parse a data line (dataline in grammar)

Parameters

sstring

The string to parse.

lookupdict, optional

A dictionary with keys == reflbls and values == tuples of operation labels which can be used for substitutions using the S<reflbl> syntax.

expected_countsint, optional

The expected number of counts to accompany the circuit on this data line. If < 0, no check is performed; otherwise raises ValueError if the number of counts does not equal expected_counts.

create_subcircuitsbool, optional

Whether to create sub-circuit-labels when parsing string representations or to just expand these into non-subcircuit labels.

Returns

circuitCircuit

The circuit.

countslist

List of counts following the circuit.

parse_dictline(s)

Parse a circuit dictionary line (dictline in grammar)

Parameters

sstring

The string to parse.

Returns

circuitLabelstring

The user-defined label to represent this circuit.

circuitTupletuple

The circuit as a tuple of operation labels.

circuitStrstring

The circuit as represented as a string in the dictline.

circuitLineLabelstuple

The line labels of the cirucit.

occurrenceobject

Circuit’s occurrence id, or None if there is none.

compilable_indicestuple or None

A tuple of layer indices (into label_tuple) marking the layers that can be “compiled”, and are not followed by a barrier so they can be compiled with following layers. This is non-None only when there are explicit markers within the circuit string indicating the presence or absence of barriers.

parse_stringfile(filename, line_labels='auto', num_lines=None, create_subcircuits=True)

Parse a circuit list file.

Parameters

filenamestring

The file to parse.

line_labelsiterable, optional

The (string valued) line labels used to initialize Circuit objects when line label information is absent from the one-line text representation contained in filename. If ‘auto’, then line labels are taken to be the list of all state-space labels present in the circuit’s layers. If there are no such labels then the special value ‘*’ is used as a single line label.

num_linesint, optional

Specify this instead of line_labels to set the latter to the integers between 0 and num_lines-1.

create_subcircuitsbool, optional

Whether to create sub-circuit-labels when parsing string representations or to just expand these into non-subcircuit labels.

Returns

list of Circuits

The circuits read from the file.

parse_dictfile(filename)

Parse a circuit dictionary file.

Parameters

filenamestring

The file to parse.

Returns

dict

Dictionary with keys == circuit labels and values == Circuits.

parse_datafile(filename, show_progress=True, collision_action='aggregate', record_zero_counts=True, ignore_zero_count_lines=True, with_times='auto')

Parse a data set file into a DataSet object.

Parameters

filenamestring

The file to parse.

show_progressbool, optional

Whether or not progress should be displayed

collision_action{“aggregate”, “keepseparate”}

Specifies how duplicate circuits should be handled. “aggregate” adds duplicate-circuit counts, whereas “keepseparate” tags duplicate circuits by setting their .occurrence IDs to sequential positive integers.

record_zero_countsbool, optional

Whether zero-counts are actually recorded (stored) in the returned DataSet. If False, then zero counts are ignored, except for potentially registering new outcome labels.

ignore_zero_count_linesbool, optional

Whether circuits for which there are no counts should be ignored (i.e. omitted from the DataSet) or not.

with_timesbool or “auto”, optional

Whether to the time-stamped data format should be read in. If “auto”, then this format is allowed but not required. Typically you only need to set this to False when reading in a template file.

Returns

DataSet

A static DataSet object.

parse_multidatafile(filename, show_progress=True, collision_action='aggregate', record_zero_counts=True, ignore_zero_count_lines=True)

Parse a multiple data set file into a MultiDataSet object.

Parameters

filenamestring

The file to parse.

show_progressbool, optional

Whether or not progress should be displayed

collision_action{“aggregate”, “keepseparate”}

Specifies how duplicate circuits should be handled. “aggregate” adds duplicate-circuit counts, whereas “keepseparate” tags duplicate circuits by setting their .occurrence IDs to sequential positive integers.

record_zero_countsbool, optional

Whether zero-counts are actually recorded (stored) in the returned MultiDataSet. If False, then zero counts are ignored, except for potentially registering new outcome labels.

ignore_zero_count_linesbool, optional

Whether circuits for which there are no counts should be ignored (i.e. omitted from the MultiDataSet) or not.

Returns

MultiDataSet

A MultiDataSet object.

parse_tddatafile(filename, show_progress=True, record_zero_counts=True, create_subcircuits=True)

Parse a timstamped data set file into a DataSet object.

Parameters

filenamestring

The file to parse.

show_progressbool, optional

Whether or not progress should be displayed

record_zero_countsbool, optional

Whether zero-counts are actually recorded (stored) in the returned DataSet. If False, then zero counts are ignored, except for potentially registering new outcome labels.

create_subcircuitsbool, optional

Whether to create sub-circuit-labels when parsing string representations or to just expand these into non-subcircuit labels.

Returns

DataSet

A static DataSet object.

pygsti.io.stdinput.parse_model(filename)

Parse a model file into a Model object.

Parameters

filenamestring

The file to parse.

Returns

Model