pygsti.circuits.circuitparser

Implementations of a text parser for reading GST input files.

Submodules

Package Contents

Classes

CircuitLexer

Lexer for matching and interpreting text-format operation sequences

CircuitParser

Parser for text-format operation sequences

Attributes

warn_msg

pygsti.circuits.circuitparser.warn_msg
class pygsti.circuits.circuitparser.CircuitLexer

Lexer for matching and interpreting text-format operation sequences

tokens = "('EXPOP', 'MULTOP', 'INTEGER', 'NOP', 'GATE', 'INSTRMT', 'PREP', 'POVM', 'REFLBL', 'OPENBR',..."
t_EXPOP = "'\\\\^'"
t_MULTOP = "'\\\\*'"
t_OPENBR = "'\\\\['"
t_CLOSEBR = "'\\\\]'"
t_LPAREN = "'\\\\('"
t_RPAREN = "'\\\\)'"
t_COLON = "'\\\\:'"
t_SEMICOLON = "'\\\\;'"
t_EXCLAM = "'\\\\!'"
t_ignore = "' \\t'"
static make_label(s)
static t_GATE(t)

'G[a-z0-9_]+(;[a-zQ0-9_\./]+)*(:[a-zQ0-9_]+)*(![0-9\.]+)?'

static t_INSTRMT(t)

'I[a-z0-9_]+(![0-9\.]+)?'

static t_PREP(t)

'rho[a-z0-9_]+(![0-9\.]+)?'

static t_POVM(t)

'M[a-z0-9_]+(![0-9\.]+)?'

static t_STRINGIND(t)

'S(?=\s*\<)'

static t_REFLBL(t)

'<\s*[a-zA-Z0-9_]+\s*>'

static t_NOP(t)

'\{\}'

static t_INTEGER(t)

'\d+'

static t_error(t)
class pygsti.circuits.circuitparser.CircuitParser(lexer_object=None, lookup=None)

Bases: object

Parser for text-format operation sequences

property lookup

The lookup dictionary for expanding references

tokens
mode = "'simple'"
p_strref(p)

strref : STRINGIND REFLBL

static p_slcref_slice(p)

slcref : strref OPENBR INTEGER COLON INTEGER CLOSEBR

static p_slcref(p)

slcref : strref

static p_subcircuit_singlelayer(p)

subcircuit : OPENBR layer CLOSEBR

static p_subcircuit_string(p)

subcircuit : LPAREN layer RPAREN

static p_layerable(p)

layerable : GATE | INSTRMT

static p_layerable_subcircuit(p)

layerable : subcircuit

static p_layerable_subcircuit_expop(p)

layerable : subcircuit EXPOP INTEGER

static p_layer_layerable(p)

layer : layerable

static p_layer_str(p)

layer : layer layerable

static p_layer(p)

layer : layer MULTOP layerable

static p_expable_paren(p)

expable : LPAREN string RPAREN

static p_expable_layer(p)

expable : OPENBR layer CLOSEBR

static p_expable_empty_layer(p)

expable : OPENBR CLOSEBR

static p_expable_single(p)

expable : GATE | INSTRMT | NOP

static p_expable(p)

expable : slcref

static p_expdstr_expop(p)

expdstr : expable EXPOP INTEGER

static p_expdstr(p)

expdstr : expable

static p_string_expdstr(p)

string : expdstr

static p_string_str(p)

string : string expdstr

static p_string(p)

string : string MULTOP expdstr

static p_pstring(p)

pstring : string

static p_pstring_prep(p)

pstring : PREP string

static p_ppstring(p)

ppstring : pstring

static p_ppstring_povm(p)

ppstring : pstring POVM

static p_error(p)
ply_parse(code, create_subcircuits=True)

Perform lexing and parsing of code.

Parameters

codestr

A circuit encoded as a single-line string

Returns

layer_labelstuple

A tuple of the layer-labels of the circuit

line_labelstuple

A tuple of the line labels of the circuit.