quimb.tensor.circuit.qasm¶
Parsing of qsim and OpenQASM 2/3 into circuit gate lists.
Functions¶
|
Parse a 'qsim' input format string into circuit information. |
|
Parse a qsim file. |
|
Parse a qsim url. |
|
Split, strip and filter a string by a given character into a list. |
|
Replace multiple substrings in a string. |
|
Replace whole identifier-like tokens in an OpenQASM fragment. |
|
|
|
|
|
|
|
Parse the string contents of an OpenQASM 2.0 file. This parser does not |
|
Parse an OpenQASM 2.0 file. |
|
Parse an OpenQASM 2.0 url. |
|
Parse an OpenQASM 3.0 program from a string. |
|
Parse an OpenQASM 3.0 file. |
|
Parse an OpenQASM 3.0 program from a URL. |
Module Contents¶
- quimb.tensor.circuit.qasm.parse_qsim_str(contents)[source]¶
Parse a ‘qsim’ input format string into circuit information.
The format is described here: https://quantumai.google/qsim/input_format.
- Parameters:
contents (str) – The full string of the qsim file.
- Returns:
circuit_info – Information about the circuit:
circuit_info[‘n’]: the number of qubits
circuit_info[‘n_gates’]: the number of gates in total
circuit_info[‘gates’]: list[list[str]], list of gates, each of which is a list of strings read from a line of the qsim file.
- Return type:
- quimb.tensor.circuit.qasm.to_clean_list(s, delimiter)[source]¶
Split, strip and filter a string by a given character into a list.
- quimb.tensor.circuit.qasm.multi_replace(s, replacements)[source]¶
Replace multiple substrings in a string.
- quimb.tensor.circuit.qasm._openqasm_replace_tokens(s, replacements)[source]¶
Replace whole identifier-like tokens in an OpenQASM fragment.
- quimb.tensor.circuit.qasm.parse_openqasm2_str(contents)[source]¶
Parse the string contents of an OpenQASM 2.0 file. This parser does not support classical control flow is not guaranteed to check the full openqasm grammar.
- quimb.tensor.circuit.qasm.parse_openqasm2_file(fname, **kwargs)[source]¶
Parse an OpenQASM 2.0 file.
- quimb.tensor.circuit.qasm.parse_openqasm3_str(contents)[source]¶
Parse an OpenQASM 3.0 program from a string.
This parser is dependency free and supports a practical subset of OpenQASM 3 for circuit import, including qubit declarations, input declarations, arithmetic expressions, custom gates, and register broadcasting.
- Parameters:
contents (str) – The OpenQASM 3 source code to parse.
- Returns:
A dictionary describing the circuit with the following entries:
"n": total number of qubits."sitemap": mapping from OpenQASM qubit names to qubit indices."gates": parsed sequence ofGateobjects."n_gates": total number of parsed gates."inputs": tuple of symbolic input names declared withinput."symbols": mapping of symbolic names to their current values or symbolic placeholders."expressions": mapping from gate indices to symbolic parameter expressions requiring later binding.
- Return type:
- Raises:
NotImplementedError – If the program uses unsupported OpenQASM 3 features such as control flow, calibration blocks, output declarations, or unsupported operations.
SyntaxError – If the source contains an instruction that does not match the supported grammar subset.
- quimb.tensor.circuit.qasm.parse_openqasm3_file(fname, **kwargs)[source]¶
Parse an OpenQASM 3.0 file.
- Parameters:
fname (str or path-like) – Path to the OpenQASM 3 file.
**kwargs – Forwarded to
parse_openqasm3_str().
- Returns:
The parsed circuit information returned by
parse_openqasm3_str().- Return type:
- quimb.tensor.circuit.qasm.parse_openqasm3_url(url, **kwargs)[source]¶
Parse an OpenQASM 3.0 program from a URL.
- Parameters:
url (str) – URL pointing to an OpenQASM 3 source file.
**kwargs – Forwarded to
parse_openqasm3_str().
- Returns:
The parsed circuit information returned by
parse_openqasm3_str().- Return type: