Liking cljdoc? Tell your friends :D

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

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

circuit-to-qasmclj

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

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

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

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-expression-paramsclj

(extract-expression-params expr-list)

Extract parameters from expression list (for parametric gates).

Extract parameters from expression list (for parametric gates).
sourceraw docstring

extract-gate-operandsclj

(extract-gate-operands args)

Extract qubit operands from gate call arguments.

Extract qubit operands from gate call arguments.
sourceraw docstring

extract-number-from-expressionclj

(extract-number-from-expression expr)

Extract a number from an expression parse tree.

Extract a number from an expression parse tree.
sourceraw docstring

extract-qreg-sizeclj

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

gate-to-qasm2clj

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

parse-gate-callclj

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

parse-result-pragmaclj

(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
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 2.0 code into a quantum circuit.

Returns a map with:

  • :circuit - the quantum circuit object
  • :result-specs - any measurement or result specifications
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
sourceraw docstring

qasm2-parserclj

source

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