QASM2 parser and emitter using Instaparse.
This namespace provides functions to parse OpenQASM 2.0 quantum circuits into the qclojure domain model and emit qclojure circuits back to QASM2 format.
QASM2 parser and emitter using Instaparse. This namespace provides functions to parse OpenQASM 2.0 quantum circuits into the qclojure domain model and emit qclojure circuits back to QASM2 format.
(circuit-to-qasm circuit)
(circuit-to-qasm circuit result-specs)
Convert a quantum circuit to OpenQASM 2.0 code with result type support.
Parameters:
Returns: String containing QASM 2.0 code with result pragmas as comments
Convert a quantum circuit to OpenQASM 2.0 code with result type support. Parameters: - circuit: Quantum circuit to convert - result-specs: (optional) Map specifying result extraction requirements Returns: String containing QASM 2.0 code with result pragmas as comments
(collect-result-specs-from-qasm qasm-lines)
Collect all result specifications from QASM pragma comments.
Collect all result specifications from QASM pragma comments.
(extract-array-size designator)
Extract the array size from a designator parse node.
Extract the array size from a designator parse node.
(extract-expression-params expr-list)
Extract parameters from expression list (for parametric gates).
Extract parameters from expression list (for parametric gates).
(extract-gate-operands args)
Extract qubit operands from gate call arguments.
Extract qubit operands from gate call arguments.
(extract-number-from-expression expr)
Extract a number from an expression parse tree.
Extract a number from an expression parse tree.
(extract-qreg-size id-list)
Extract the qubit count from a qreg id_list structure.
Extract the qubit count from a qreg id_list structure.
(extract-qubit-index operand)
Extract qubit index from an indexed identifier.
Extract qubit index from an indexed identifier.
(gate-to-qasm2 gate)
Convert a single gate operation to QASM2 syntax using operation registry information.
Convert a single gate operation to QASM2 syntax using operation registry information.
(parse-gate-call gate-name-node args-list)
Parse QASM2 gate call and convert to circuit operation using circuit namespace functions.
Parse QASM2 gate call and convert to circuit operation using circuit namespace functions.
(parse-result-pragma pragma-line)
Parse a QClojure result pragma from QASM 2.0 comment.
Example pragmas: // #pragma qclojure result measurement shots=1000 qubits=0,1 // #pragma qclojure result expectation observable=pauli-z target=0 // #pragma qclojure result variance observable=pauli-x target=1
Parse a QClojure result pragma from QASM 2.0 comment. Example pragmas: // #pragma qclojure result measurement shots=1000 qubits=0,1 // #pragma qclojure result expectation observable=pauli-z target=0 // #pragma qclojure result variance observable=pauli-x target=1
(preprocess-qasm qasm-code)
Remove comments from QASM code while preserving structure. Removes both line comments (//) and block comments (/* */).
Remove comments from QASM code while preserving structure. Removes both line comments (//) and block comments (/* */).
(qasm-to-circuit qasm-code)
Parse OpenQASM 2.0 code into a quantum circuit.
Returns a map with:
Parse OpenQASM 2.0 code into a quantum circuit. Returns a map with: - :circuit - the quantum circuit object - :result-specs - any measurement or result specifications
(remove-block-comments qasm-code)
Remove C-style block comments (/* ... */) from QASM code.
Remove C-style block comments (/* ... */) from QASM code.
(remove-line-comments qasm-code)
Remove C++-style line comments (// ...) from QASM code. Preserves line structure to maintain line-based pragmas.
Remove C++-style line comments (// ...) from QASM code. Preserves line structure to maintain line-based pragmas.
(result-specs-to-qasm-pragmas result-specs)
Convert result specifications to QASM pragma comments for QASM2 format. Uses // comments to be compatible with QASM2 parsers.
Convert result specifications to QASM pragma comments for QASM2 format. Uses // comments to be compatible with QASM2 parsers.
(transform-parse-tree parse-tree qasm-code)
Transform the Instaparse parse tree into a circuit structure using purely functional approach.
This function uses insta/transform to process the parse tree in a functional way, collecting quantum declarations and gate operations into data structures, then building the circuit from this collected data without any mutable state.
Transform the Instaparse parse tree into a circuit structure using purely functional approach. This function uses insta/transform to process the parse tree in a functional way, collecting quantum declarations and gate operations into data structures, then building the circuit from this collected data without any mutable state.
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |