PyQASM 0.1.0-alpha
Pre-release
Pre-release
TheGupta2012
released this
28 Nov 08:24
·
13 commits
to main
since this release
Release 0.1.0-alpha (Nov 28, 2024)
Summary
Added
- Added a
dumps
andformatted_qasm
method to theQasmModule
class to allow for the conversion of aQasmModule
object to a string representation of the QASM code (#71) - Added the
populate_idle_qubits
method to theQasmModule
class to populate idle qubits with anid
gate (#72) - Added gate definitions for "c3sqrtx", "u1", "rxx", "cu3", "csx", "rccx" , "ch" , "cry", "cp", "cu", "cu1", "rzz" in
maps.py
(#74) - Added support for skipping the unrolling for externally linked gates. The
QasmModule.unroll()
method now accepts anexternal_gates
parameter which is a list of gate names that should not be unrolled (#59). Usage -
In [30]: import pyqasm
In [31]: qasm_str = """OPENQASM 3.0;
...: include "stdgates.inc";
...: gate custom q1, q2, q3{
...: x q1;
...: y q2;
...: z q3;
...: }
...:
...: qubit[4] q;
...: custom q[0], q[1], q[2];
...: cx q[1], q[2];"""
In [32]: module = pyqasm.loads(qasm_str)
In [33]: module.unroll(external_gates= ["custom"])
In [34]: pyqasm.dumps(module).splitlines()
Out[34]:
['OPENQASM 3.0;',
'include "stdgates.inc";',
'qubit[4] q;',
'custom q[0], q[1], q[2];',
'cx q[1], q[2];']
- Major Change: Added the
load
,loads
,dump
, anddumps
functions to thepyqasm
module to allow for the loading and dumping of QASM code (#76). Usage -
In [18]: import pyqasm
In [19]: qasm_str = """OPENQASM 3.0;
...: include "stdgates.inc";
...: qreg q1[2];
...: qubit[2] q2;"""
In [20]: module = pyqasm.loads(qasm_str)
In [21]: print(pyqasm.dumps(module))
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q1;
qubit[2] q2;
In [22]: file_path = "test.qasm"
In [23]: pyqasm.dump(module, file_path)
In [24]: module = pyqasm.load(file_path)
In [25]: print(pyqasm.dumps(module))
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q1;
qubit[2] q2;
- Added definitions for various gates in
maps.py
and tests for qasm formatting functions of the qbraid-sdk (#82, #84) - Added
pyqasm.accelerate
module to hold.pyx
files with Cython-based optimizations for computationally intensive functions (#83) - Added
has_barriers
method for checking if aQasmModule
object contains barriers (#85) - Added
pyqasm.cli
module withtyper
integration to enable using pyqasm as a command-line tool (#87)
$ pip install 'pyqasm[cli]'
$ pyqasm --help
Usage: pyqasm [OPTIONS] COMMAND [ARGS]...
$ pyqasm --version
pyqasm/0.1.0a1
$ pyqasm validate tests/cli/resources
tests/cli/resources/invalid1.qasm: error: Index 2 out of range for register of size 1 in qubit [validation]
Found errors in 1 file (checked 3 source files)
$ pyqasm validate tests/cli/resources --skip tests/cli/resources/invalid1.qasm
Success: no issues found in 2 source files
Improved / Modified
- Changed the
__init__
method for theQasmModule
class to only accept anopenqasm3.ast.Program
object as input (#71) - Changed
DepthNode
,QubitDepthNode
,ClbitDepthNode
, andVariable
to dataclasses.__repr__
method is therefore handled automatically and you don't need all of the redundant private / public attribute and setters (#79) - Simplified
map_qasm_op_to_callable
redundantKeyError
handling with loop (#79) - The
load
function has been renamed toloads
andload
is now used to load a QASM file.QasmModule.dumps()
has been replaced with__str__
method (#76) - Experimental Cython integration: (#83)
- Migrated
pyqasm.linalg._kronecker_factor
topyqasm.linalg_cy
with ~60% speedup - Migrated
pyqasm.linalg._so4_to_so2()
to topyqasm.linalg_cy
with ~5% speedup
- Migrated
- Changed source code directory from
./pyqasm
to./src/pyqasm
to prevents conflicts between the local source directory and the installed package in site-packages, ensuring Python's module resolution prioritizes the correct version. Required for local testing with new Cython build step (#83) - Updated the build process for
pyqasm
due to Cython integration. Wheels are now built for each platform and uploaded to PyPI along with the source distributions (#88)
Deprecated
Removed
- Removed the
from_program
method from theQasmModule
class (#71) QasmModule.formatted_qasm()
method has been removed (#76)
Fixed
- Updated docs custom CSS used for sphinx to make version stable/latest drop-down visible. Previously was set white so blended into background and wasn't visible. (#78)
- Fixed bug in
pyqasm.linalg.so_bidiagonalize()
in final dot product order (#83)
Dependencies
New Contributors
Full Changelog: v0.0.3...v0.1.0-alpha