Instead of having a large library of individual functions, have two functions loads and dumps which take OpenQASM strings to and from a pyqasm.Module object, and have all supported operations structured as methods that are performed in-place. Or, optionally specify in_place=False when calling any of the methods to return the resulting QASM string without altering the state of the Module object. This would allow chaining operations together without requiring loading a module to perform each op.
Here is a rough example of what the interface could look like:
from pyqasm import loads, dumps
qasm_str = "..." # Your QASM 3 program as a string
# Load the QASM 3 string into a module
module = loads(qasm_str)
# Print the number of qubits and classical bits in the module
print(module.num_qubits()) # <int>
print(module.num_clbits()) # <int>
# Print the circuit depth
print(module.depth()) # <int>
# Decompose the circuit to a new gate set
module.rebase(basis_gates={"h", "t", "cx"})
# Print the new depth after rebasing
print(module.depth()) # <int>
# Remove barriers from the circuit
module.remove_barriers()
# Draw the circuit using matplotlib (mpl) or other available options
module.draw(output='mpl') # Options: 'ascii', 'mpl', TBD (e.g., 'latex')
# Dump the module back to a QASM string
qasm_str_out = dumps(module)
# Make a copy of the module
module_2 = module.copy()
# Flatten gates and operations
module_2.unroll()
# Remove measurements, returning a new QASM string (if in_place=False)
qasm_str_2_out = module_2.remove_measurements(in_place=False) # Default is in_place=True
Instead of having a large library of individual functions, have two functions
loads
anddumps
which take OpenQASM strings to and from apyqasm.Module
object, and have all supported operations structured as methods that are performed in-place. Or, optionally specifyin_place=False
when calling any of the methods to return the resulting QASM string without altering the state of theModule
object. This would allow chaining operations together without requiring loading a module to perform each op.Here is a rough example of what the interface could look like: