qbraid_algorithms.qtran.QasmBuilder

class qbraid_algorithms.qtran.QasmBuilder(qubits, clbits=None, version=3)

Complete OpenQASM circuit builder for quantum programs.

This is the primary builder for creating full quantum circuits with proper OpenQASM headers, qubit/classical bit declarations, library imports, and the complete program structure. It automatically manages resource allocation and generates standards-compliant OpenQASM code.

Features:

  • Automatic OpenQASM version header generation

  • Qubit and classical bit resource management

  • Dynamic resource allocation with claim methods

  • Complete circuit structure generation

  • Library import management

  • Gate definition embedding

__init__(qubits, clbits=None, version=3)

Initialize a complete quantum circuit builder.

Creates a builder configured for generating full OpenQASM programs with the specified resources and version compatibility.

Parameters:
  • qubits – Number of qubits to allocate initially

  • clbits – Number of classical bits (defaults to qubit count if None)

  • version – OpenQASM version number (default: 3)

The builder automatically generates appropriate headers and resource declarations based on these parameters.

Methods

__init__(qubits[, clbits, version])

Initialize a complete quantum circuit builder.

build()

Generate the complete OpenQASM circuit code.

claim_clbits(number)

Dynamically allocate additional classical bits to the circuit.

claim_qubits(number)

Dynamically allocate additional qubits to the circuit.

import_library(lib_class[, annotated])

Import and initialize a quantum gate library.

program_append(line)

Append a line of code to the program with proper indentation.