quimb.tensor.circuit.qasm ========================= .. py:module:: quimb.tensor.circuit.qasm .. autoapi-nested-parse:: Parsing of qsim and OpenQASM 2/3 into circuit gate lists. Functions --------- .. autoapisummary:: quimb.tensor.circuit.qasm._convert_ints_and_floats quimb.tensor.circuit.qasm._put_registers_last quimb.tensor.circuit.qasm.parse_qsim_str quimb.tensor.circuit.qasm.parse_qsim_file quimb.tensor.circuit.qasm.parse_qsim_url quimb.tensor.circuit.qasm.to_clean_list quimb.tensor.circuit.qasm.multi_replace quimb.tensor.circuit.qasm._openqasm_replace_tokens quimb.tensor.circuit.qasm.get_openqasm2_regexes quimb.tensor.circuit.qasm.get_openqasm3_regexes quimb.tensor.circuit.qasm._openqasm_split_top_level quimb.tensor.circuit.qasm._openqasm_eval_expr quimb.tensor.circuit.qasm._is_interface_placeholder quimb.tensor.circuit.qasm._placeholder_param_vector quimb.tensor.circuit.qasm.parse_openqasm2_str quimb.tensor.circuit.qasm.parse_openqasm2_file quimb.tensor.circuit.qasm.parse_openqasm2_url quimb.tensor.circuit.qasm.parse_openqasm3_str quimb.tensor.circuit.qasm.parse_openqasm3_file quimb.tensor.circuit.qasm.parse_openqasm3_url Module Contents --------------- .. py:function:: _convert_ints_and_floats(x) .. py:function:: _put_registers_last(x) .. py:function:: parse_qsim_str(contents) Parse a 'qsim' input format string into circuit information. The format is described here: https://quantumai.google/qsim/input_format. :param contents: The full string of the qsim file. :type contents: str :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. :rtype: dict .. py:function:: parse_qsim_file(fname, **kwargs) Parse a qsim file. .. py:function:: parse_qsim_url(url, **kwargs) Parse a qsim url. .. py:function:: to_clean_list(s, delimiter) Split, strip and filter a string by a given character into a list. .. py:function:: multi_replace(s, replacements) Replace multiple substrings in a string. .. py:function:: _openqasm_replace_tokens(s, replacements) Replace whole identifier-like tokens in an OpenQASM fragment. .. py:function:: get_openqasm2_regexes() .. py:function:: get_openqasm3_regexes() .. py:function:: _openqasm_split_top_level(s, sep=',') .. py:function:: _openqasm_eval_expr(expr, env) .. py:function:: _is_interface_placeholder(x) .. py:function:: _placeholder_param_vector(values) .. py:function:: parse_openqasm2_str(contents) 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. .. py:function:: parse_openqasm2_file(fname, **kwargs) Parse an OpenQASM 2.0 file. .. py:function:: parse_openqasm2_url(url, **kwargs) Parse an OpenQASM 2.0 url. .. py:function:: parse_openqasm3_str(contents) 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. :param contents: The OpenQASM 3 source code to parse. :type contents: str :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 of :class:`Gate` objects. - ``"n_gates"``: total number of parsed gates. - ``"inputs"``: tuple of symbolic input names declared with ``input``. - ``"symbols"``: mapping of symbolic names to their current values or symbolic placeholders. - ``"expressions"``: mapping from gate indices to symbolic parameter expressions requiring later binding. :rtype: dict :raises NotImplementedError: If the program uses unsupported OpenQASM 3 features such as control flow, calibration blocks, output declarations, or unsupported operations. :raises SyntaxError: If the source contains an instruction that does not match the supported grammar subset. .. py:function:: parse_openqasm3_file(fname, **kwargs) Parse an OpenQASM 3.0 file. :param fname: Path to the OpenQASM 3 file. :type fname: str or path-like :param \*\*kwargs: Forwarded to :func:`parse_openqasm3_str`. :returns: The parsed circuit information returned by :func:`parse_openqasm3_str`. :rtype: dict .. py:function:: parse_openqasm3_url(url, **kwargs) Parse an OpenQASM 3.0 program from a URL. :param url: URL pointing to an OpenQASM 3 source file. :type url: str :param \*\*kwargs: Forwarded to :func:`parse_openqasm3_str`. :returns: The parsed circuit information returned by :func:`parse_openqasm3_str`. :rtype: dict