Liking cljdoc? Tell your friends :D

org.soulspace.qclojure.application.format.qasm3-parser

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.
raw docstring

apply-functionclj

(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.
sourceraw docstring

bit-rotlclj

(bit-rotl x dist)

Rotate bits left (64-bit semantics).

Rotate bits left (64-bit semantics).
sourceraw docstring

bit-rotrclj

(bit-rotr x dist)

Rotate bits right (64-bit semantics).

Rotate bits right (64-bit semantics).
sourceraw docstring

circuit-to-qasmclj

(circuit-to-qasm circuit)
(circuit-to-qasm circuit result-specs)

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

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
sourceraw docstring

collect-result-specs-from-qasmclj

(collect-result-specs-from-qasm qasm-lines)

Collect all result specifications from QASM pragma comments.

Collect all result specifications from QASM pragma comments.
sourceraw docstring

constantsclj

Constants according to OpenQASM 3 (used in expression evaluation)

Constants according to OpenQASM 3 (used in expression evaluation)
sourceraw docstring

double-modclj

(double-mod a b)

Floating-point modulus on doubles.

Floating-point modulus on doubles.
sourceraw docstring

evaluate-expressionclj

(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.
sourceraw docstring

extract-array-sizeclj

(extract-array-size designator)

Extract the array size from a designator parse node.

Extract the array size from a designator parse node.
sourceraw docstring

extract-gate-nameclj

(extract-gate-name gate-call-node)

Extract gate name from gate call node.

Extract gate name from gate call node.
sourceraw docstring

extract-gate-operandsclj

(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 ...] ...].
sourceraw docstring

extract-gate-parametersclj

(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.
sourceraw docstring

extract-qubit-indexclj

(extract-qubit-index operand)

Extract qubit index from an indexed identifier.

Extract qubit index from an indexed identifier.
sourceraw docstring

fold-infixclj

(fold-infix x more apply-op)

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.
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.
sourceraw docstring

gate-to-qasm3clj

(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.
sourceraw docstring

numeric-promoteclj

(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.
sourceraw docstring

op-strclj

(op-str op)

Convert an operation identifier to string.

Convert an operation identifier to string.
sourceraw docstring

parse-gate-callclj

(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.
sourceraw docstring

parse-result-pragmaclj

(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
sourceraw docstring

parse-simple-integerclj

(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.
sourceraw docstring

powclj

(pow a b)

Power function for numeric types.

Power function for numeric types.
sourceraw docstring

preprocess-qasmclj

(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 (/* */).
sourceraw docstring

qasm-to-circuitclj

(qasm-to-circuit qasm-code)

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
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
sourceraw docstring

remove-block-commentsclj

(remove-block-comments qasm-code)

Remove C-style block comments (/* ... */) from QASM code.

Remove C-style block comments (/* ... */) from QASM code.
sourceraw docstring

remove-line-commentsclj

(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.
sourceraw docstring

result-specs-to-qasm-pragmasclj

(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.
sourceraw docstring

to-boolclj

(to-bool v)

Convert a value to boolean.

Convert a value to boolean.
sourceraw docstring

to-doubleclj

(to-double v)

Convert a value to double.

Convert a value to double.
sourceraw docstring

to-longclj

(to-long v)

Convert a value to long integer.

Convert a value to long integer.
sourceraw docstring

transform-parse-treeclj

(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.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close