Key Features: Load algorithms as PyQASM modules and QASM files

qBraid Algorithms provides a collection of quantum algorithms that can be loaded as PyQASM modules, or you can generate .qasm files to use them as subroutines in your own circuits.

Loading Algorithms as PyQASM Modules

To load an algorithm as a PyQASM module, use the load_algorithm function from the qbraid_algorithms package, passing algorithm-specific parameters. For example, to load the Quantum Fourier Transform (QFT) algorithm:
from qbraid_algorithms import qft

qft_module = qft.load_algorithm(3) # Load QFT for 3 qubits
Now, you can perform operations with the PyQASM module, such as unrolling, and converting back to a QASM string:
qft_module.unroll()
qasm_str = pyqasm.dumps(qft_module)

Loading Algorithms as .qasm Files

In order to utilize algorithms as subroutines in your own circuits, use the generate_subroutine function for your desired algorithm. By passing algorithm-specific parameters, and optionally a desired output path, you can generate a .qasm file containing a subroutine for the parameterized circuit. For example, to generate a QFT subroutine for 4 qubits:
from qbraid_algorithms import qft, iqft
path = "path/to/output" # Specify your desired output path
qft.generate_subroutine(4) # Generate 4-qubit QFT in the current directory
iqft.generate_subroutine(4, path=path) # Generate 4-qubit IQFT in specified path

To utilize the generated subroutine in your own circuit, include the generated .qasm file, and call the subroutine on an qubit register of the size specified when generating the subroutine. For example, after running
qft.generate_subroutine(4)
you can append include "qft.qasm"; to your OpenQASM file, and call the subroutine. For example:
OPENQASM 3.0;
include "qft.qasm";

qubit[4] q;
bit[4] c;

qft(q);
measure q -> c;