qpandalite.originir package

Submodules

qpandalite.originir.originir_base_parser module

class qpandalite.originir.originir_base_parser.OriginIR_BaseParser[source]

Bases: object

property originir
parse(originir_str)[source]
to_extended_originir()[source]
qpandalite.originir.originir_base_parser.opcode_to_line(opcode)[source]

qpandalite.originir.originir_line_parser module

class qpandalite.originir.originir_line_parser.OriginIR_Parser[source]

Bases: object

blank = ' *'
cid = 'c *\\[ *(\\d+) *\\]'
comma = ','
static handle_1q(line)[source]
static handle_1q1p(line)[source]
static handle_1q2p(line)[source]
static handle_1q3p(line)[source]
static handle_1q4p(line)[source]
static handle_2q(line)[source]
static handle_2q1p(line)[source]
static handle_3q(line)[source]
static handle_barrier(line)[source]
static handle_control(line)[source]

Parse a line to extract control qubits information and the type of control operation.

This function analyzes a given line of text to identify and extract information about control qubits and determine whether the line represents the beginning of a control operation (CONTROL) or the end of a control operation (ENDCONTROL) in OriginIR language.

Parameters:

line (str) – The line of text to be parsed for control qubit information.

Returns:

A tuple where the first element is a string indicating the control operation type (“CONTROL” or “ENDCONTROL”) and the second element is a list of integers representing the parsed control qubits.

Return type:

tuple of (str, list)

Notes

The function relies on the regexp_control regular expression to match the CONTROL or ENDCONTROL patterns in OriginIR language. This regular expression should be predefined and properly constructed to capture the necessary information from the line.

static handle_dagger(line)[source]

Parse a line to identify DAGGER or ENDDAGGER commands in OriginIR.

This function checks a line of text to determine if it contains a command related to the start or end of a DAGGER operation block in the OriginIR language.

Parameters:

line (str) – The line of text to be parsed.

Returns:

Returns “DAGGER” if the line is a DAGGER command, “ENDDAGGER” if it’s an ENDDAGGER command, or None if neither command is present.

Return type:

str or None

Notes

The DAGGER command in OriginIR denotes the start of a block where the operations are to be applied in reverse order with conjugate transposition (dagger operation). The ENDDAGGER command signifies the end of such a block.

static handle_measure(line)[source]
lbracket = '\\('
opname = '([A-Za-z][A-Za-z\\d]*)'
parameter = '([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?)'
static parse_line(line)[source]
qid = 'q *\\[ *(\\d+) *\\]'
rbracket = '\\)'
regexp_1q = re.compile('^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\]$')
regexp_1q1p = re.compile('^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *\\( *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *\\)$')
regexp_1q1p_str = '^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *\\( *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *\\)$'
regexp_1q2p = re.compile('^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *\\( *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *\\)$')
regexp_1q2p_str = '^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *\\( *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *\\)$'
regexp_1q3p = re.compile('^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *\\( *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *\\)$')
regexp_1q3p_str = '^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *\\( *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *\\)$'
regexp_1q4p = re.compile('^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *\\( *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*))
regexp_1q4p_str = '^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *\\( *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *, *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *\\)$'
regexp_1q_str = '^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\]$'
regexp_2q = re.compile('^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *q *\\[ *(\\d+) *\\]$')
regexp_2q1p = re.compile('^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *q *\\[ *(\\d+) *\\] *, *\\( *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *\\)$')
regexp_2q1p_str = '^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *q *\\[ *(\\d+) *\\] *, *\\( *([-+]?\\d+(\\.\\d*)?([eE][-+]?\\d+)?) *\\)$'
regexp_2q_str = '^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *q *\\[ *(\\d+) *\\]$'
regexp_3q = re.compile('^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *q *\\[ *(\\d+) *\\] *, *q *\\[ *(\\d+) *\\]$')
regexp_3q_str = '^([A-Za-z][A-Za-z\\d]*) *q *\\[ *(\\d+) *\\] *, *q *\\[ *(\\d+) *\\] *, *q *\\[ *(\\d+) *\\]$'
regexp_barrier = re.compile('^BARRIER(( *q *\\[ *(\\d+) *\\] *,)* *q *\\[ *(\\d+) *\\] *)$')
regexp_barrier_str = '^BARRIER(( *q *\\[ *(\\d+) *\\] *,)* *q *\\[ *(\\d+) *\\] *)$'
regexp_control = re.compile('^(CONTROL|ENDCONTROL)(( *q *\\[ *(\\d+) *\\] *,)* *q *\\[ *(\\d+) *\\] *)$')
regexp_control_str = '^(CONTROL|ENDCONTROL)(( *q *\\[ *(\\d+) *\\] *,)* *q *\\[ *(\\d+) *\\] *)$'
regexp_meas = re.compile('^MEASURE *q *\\[ *(\\d+) *\\] *, *c *\\[ *(\\d+) *\\]$')
regexp_measure_str = '^MEASURE *q *\\[ *(\\d+) *\\] *, *c *\\[ *(\\d+) *\\]$'
regexp_qid = re.compile('q *\\[ *(\\d+) *\\]')

Module contents