QASM3 parser and emitter using Instaparse.
This namespace provides functions to parse OpenQASM 3.0 quantum circuits into the qclojure domain model and emit qclojure circuits back to QASM3 format.
QASM3 parser and emitter using Instaparse. This namespace provides functions to parse OpenQASM 3.0 quantum circuits into the qclojure domain model and emit qclojure circuits back to QASM3 format.
(apply-function fname args)
Apply a built-in QASM3 function to arguments. Supports common math functions and integer/bitwise operations. Arguments are already evaluated to Clojure values. Returns the computed value or throws if unsupported.
Apply a built-in QASM3 function to arguments. Supports common math functions and integer/bitwise operations. Arguments are already evaluated to Clojure values. Returns the computed value or throws if unsupported.
(bit-rotl x dist)
Rotate bits left (64-bit semantics).
Rotate bits left (64-bit semantics).
(bit-rotr x dist)
Rotate bits right (64-bit semantics).
Rotate bits right (64-bit semantics).
(circuit-to-qasm circuit)
(circuit-to-qasm circuit result-specs)
Convert a quantum circuit to OpenQASM 3.0 code with result type support.
Parameters:
Returns: String containing QASM 3.0 code with result pragmas
Convert a quantum circuit to OpenQASM 3.0 code with result type support. Parameters: - circuit: Quantum circuit to convert - result-specs: (optional) Map specifying result extraction requirements Returns: String containing QASM 3.0 code with result pragmas
(collect-result-specs-from-qasm qasm-lines)
Collect all result specifications from QASM pragma comments.
Collect all result specifications from QASM pragma comments.
Constants according to OpenQASM 3 (used in expression evaluation)
Constants according to OpenQASM 3 (used in expression evaluation)
(double-mod a b)
Floating-point modulus on doubles.
Floating-point modulus on doubles.
(evaluate-expression expr-tokens)
Evaluate a QASM3 mathematical expression to a numeric value. Input is an Instaparse subtree rooted at :expression (or any expression non-terminal). Supports OpenQASM 3 operators (precedence/associativity), numeric/boolean literals, built-in constants (pi, τ/tau, euler/ℇ) and common built-in functions on const values.
Returns Clojure numbers/booleans. Bitwise ops use 64-bit semantics. Unknown identifiers are not resolved and will throw.
Evaluate a QASM3 mathematical expression to a numeric value. Input is an Instaparse subtree rooted at :expression (or any expression non-terminal). Supports OpenQASM 3 operators (precedence/associativity), numeric/boolean literals, built-in constants (pi, τ/tau, euler/ℇ) and common built-in functions on const values. Returns Clojure numbers/booleans. Bitwise ops use 64-bit semantics. Unknown identifiers are not resolved and will throw.
(extract-array-size designator)
Extract the array size from a designator parse node.
Extract the array size from a designator parse node.
(extract-gate-name gate-call-node)
Extract gate name from gate call node.
Extract gate name from gate call node.
(extract-gate-operands gate-operand-list-node)
Extract qubit operand indices from a gate_operand_list parse node. Expects a node like [:gate_operand_list [:gate_operand ...] ...].
Extract qubit operand indices from a gate_operand_list parse node. Expects a node like [:gate_operand_list [:gate_operand ...] ...].
(extract-gate-parameters expression-list-node)
Extract parameter values from an Instaparse expression_list node. Expects a parse node of the form [:expression_list expr1 expr2 ...]. Returns a vector of evaluated parameter values.
Extract parameter values from an Instaparse expression_list node. Expects a parse node of the form [:expression_list expr1 expr2 ...]. Returns a vector of evaluated parameter values.
(extract-qubit-index operand)
Extract qubit index from an indexed identifier.
Extract qubit index from an indexed identifier.
(fold-infix x more apply-op)
Helper to fold left-associative operator lists, where 'more' can be
Helper to fold left-associative operator lists, where 'more' can be - alternating op rhs children, or - a single sequential group of alternating op rhs children.
(gate-to-qasm3 gate)
Convert a single gate operation to QASM3 syntax using operation registry information.
Convert a single gate operation to QASM3 syntax using operation registry information.
(numeric-promote a b)
Promote two numeric values to a common type (long or double). If either is floating-point, promote both to double. Otherwise, promote both to long.
Promote two numeric values to a common type (long or double). If either is floating-point, promote both to double. Otherwise, promote both to long.
(op-str op)
Convert an operation identifier to string.
Convert an operation identifier to string.
(parse-gate-call gate-name-node & args)
Parse QASM gate call and convert to circuit operation using circuit namespace functions.
Parse QASM gate call and convert to circuit operation using circuit namespace functions.
(parse-result-pragma pragma-line)
Parse a QClojure result pragma from QASM 3.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 3.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-simple-integer tokens)
Parse a simple integer from parse tree tokens. Only handles DecimalIntegerLiteral, not complex expressions.
Parse a simple integer from parse tree tokens. Only handles DecimalIntegerLiteral, not complex expressions.
(pow a b)
Power function for numeric types.
Power function for numeric types.
(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 3.0 code into a quantum circuit.
Returns a map with:
Parse OpenQASM 3.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 3.0 pragma comments.
Convert result specifications to QASM 3.0 pragma comments.
(to-long v)
Convert a value to long integer.
Convert a value to long integer.
(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 |