Skip to content

Commit b146c8a

Browse files
committed
Refactor documentation and improve clarity across multiple modules
1 parent 8d1197a commit b146c8a

8 files changed

Lines changed: 75 additions & 76 deletions

File tree

qbraid_algorithms/bernstein_vazirani/bernvaz.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ def generate_program(bitstring: Union[str, list[int]]) -> QasmModule:
3333
Load the Bernstein-Vazirani circuit as a pyqasm module.
3434
3535
Args:
36-
bitstring (Union[str, list[int]]): The hidden bitstring `s` as a string of '0's
37-
and '1's
36+
bitstring (Union[str, list[int]]): The hidden bitstring `s` as a string of '0's and '1's
3837
3938
Returns:
40-
(PyQasm Module) pyqasm module containing the Bernstein-Vazirani circuit
39+
PyQASM module containing the Bernstein-Vazirani circuit
4140
"""
4241

4342
# Load the Bernstein-Vazirani QASM files into a staging directory

qbraid_algorithms/iqft/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
1 & 1 & 1 & \\cdots & 1 \\\\
5454
1 & \\omega_n^{-1} & \\omega_n^{-2} & \\cdots & \\omega_n^{-(2^n-1)} \\\\
5555
\\vdots & \\vdots & \\vdots & \\ddots & \\vdots \\\\
56-
1 & \\omega_n^{-(2^n-1)} & \\omega_n^{-2(2^n-1)} & \\cdots & \\omega_n^{-(2^n-1)^2}
56+
1 & \\omega_n^{-(2^n-1)} & \\omega_n^{-2(2^n-1)} & \\cdots & \\omega_n^{-(2^n-1)(2^n-1)}
5757
\\end{pmatrix}`
5858
5959

qbraid_algorithms/qft/qft.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,8 @@
1313
# limitations under the License.
1414

1515
"""
16-
Quantum Fourier Transform (QFT) Algorithm Implementation
16+
Quantum Fourier Transform (QFT) Algorithm Interface
1717
18-
This module provides a complete implementation of the Quantum Fourier Transform,
19-
a fundamental building block for many quantum algorithms.
20-
21-
The QFT transforms quantum states from the computational basis to the Fourier basis
22-
by applying Hadamard gates and controlled phase rotations. It's essential for
23-
algorithms like Shor's algorithm and quantum phase estimation, providing the
24-
quantum analogue of the classical discrete Fourier transform.
25-
26-
Formulation:
27-
The QFT transforms a quantum state |j⟩ to |ψ⟩ = 1/√N Σₖ₌₀^(N-1) e^(2πijk/N)|k⟩
28-
where N = 2ⁿ for n qubits. The circuit implements this using Hadamard gates H
29-
and controlled phase rotations R_k with phase φ = 2π/2^k. The total circuit
30-
depth is O(n²) with O(n²) gates.
3118
"""
3219
import os
3320
import shutil
@@ -45,6 +32,7 @@
4532
def generate_program(num_qubits: int) -> QasmModule:
4633
"""
4734
Load the Quantum Fourier Transform circuit as a pyqasm module.
35+
4836
Args:
4937
num_qubits (int): The number of qubits for the QFT.
5038

qbraid_algorithms/qft/qft_lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
"""
15-
Quantum Fourier Transform (QFT) Algorithm Implementation
15+
Quantum Fourier Transform (QFT) Library Implementation
1616
1717
"""
1818

qbraid_algorithms/qpe/phase_est.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
class PhaseEstimationLibrary(GateLibrary):
3333
"""
3434
Library to implement phase estimation circuits directly related to classical
35-
phase estimation algorithms. Iterative phase estimation will be supported via
36-
the Rodeo package. This library supports both static and time-dependent Hamiltonians.
35+
phase estimation algorithms.
36+
3737
"""
3838

3939
def __init__(self, *args, **kwargs):

qbraid_algorithms/qtran/gate_library.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
built to inject definitions into whatever FileBuilder class it is connected to.
2323
2424
Key (Base) Features:
25-
- Gate application with controls and phases
26-
- Measurements and classical bit operations
27-
- Control flow (loops, conditionals)
28-
- Gate and subroutine definitions
29-
- Code generation and scope management
25+
26+
- Gate application with controls and phases
27+
- Measurements and classical bit operations
28+
- Control flow (loops, conditionals)
29+
- Gate and subroutine definitions
30+
- Code generation and scope management
3031
3132
Class Extensions:
3233
- std_gates
@@ -41,11 +42,12 @@ class GateLibrary:
4142
4243
Core class for quantum gate operations and circuit building.
4344
Provides fundamental operations for:
44-
- Gate application with controls and phases
45-
- Measurements and classical bit operations
46-
- Control flow (loops, conditionals)
47-
- Gate and subroutine definitions
48-
- Code generation and scope management
45+
46+
- Gate application with controls and phases
47+
- Measurements and classical bit operations
48+
- Control flow (loops, conditionals)
49+
- Gate and subroutine definitions
50+
- Code generation and scope management
4951
5052
"""
5153

@@ -210,10 +212,11 @@ def begin_loop(self, iterator, ident: str = "i"):
210212
LOOPS
211213
212214
Start a loop block with various iteration patterns:
213-
- int: for int i in [0:n]
214-
- (start, end): for int i in [start:end]
215-
- (start, step, end): for int i in [start:end:step]
216-
- string: custom loop syntax
215+
216+
- int: for int i in [0:n]
217+
- (start, end): for int i in [start:end]
218+
- (start, step, end): for int i in [start:end:step]
219+
- string: custom loop syntax
217220
218221
Args:
219222
iterator: Loop specification (int, tuple, or string)
@@ -432,9 +435,10 @@ class std_gates(GateLibrary):
432435
Implementation of std_lib quantum gates following OpenQASM 3.0 standards.
433436
434437
Available Gates:
435-
- Single-qubit: phase, x, y, z, h, s, sdg, sx
436-
- Two-qubit: cx, cy, cz, cp, crx, cry, crz, swap
437-
- Multi-qubit: ccx (Toffoli), cswap (Fredkin)
438+
439+
- Single-qubit: phase, x, y, z, h, s, sdg, sx
440+
- Two-qubit: cx, cy, cz, cp, crx, cry, crz, swap
441+
- Multi-qubit: ccx (Toffoli), cswap (Fredkin)
438442
"""
439443

440444
# Standard gate set from OpenQASM 3.0 specification

qbraid_algorithms/qtran/module_loader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def qasm_pipe(func: Callable) -> Callable:
3838
then writes the function's (file_name, program_string) output to a .qasm file.
3939
4040
The decorated function should:
41-
1. Accept 'path' and 'quiet' as keyword arguments
42-
2. Return a tuple of (file_name, program_string)
41+
42+
1. Accept 'path' and 'quiet' as keyword arguments
43+
2. Return a tuple of (file_name, program_string)
4344
4445
The decorator will create a file named "{file_name}.qasm" and write the program_string to it.
4546
"""

qbraid_algorithms/qtran/qasm_builder.py

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
structure/semantics requirements unique to each file
2323
2424
Key Features:
25-
- Automatic scope and indentation management
26-
- Library import and gate definition tracking
27-
- Multiple output formats (QASM circuits, includes, gate definitions)
28-
- Resource allocation for qubits and classical bits
29-
- Extensible design for custom quantum libraries
25+
26+
- Automatic scope and indentation management
27+
- Library import and gate definition tracking
28+
- Multiple output formats (QASM circuits, includes, gate definitions)
29+
- Resource allocation for qubits and classical bits
30+
- Extensible design for custom quantum libraries
3031
3132
Class Extensions:
32-
- GateBuilder
33-
- QasmBuilder
34-
- IncludeBuilder
33+
- GateBuilder
34+
- QasmBuilder
35+
- IncludeBuilder
3536
"""
3637

3738

@@ -44,23 +45,25 @@ class FileBuilder:
4445
for specialized builders that generate different types of OpenQASM output.
4546
4647
The FileBuilder maintains several key data structures:
47-
- imports: List of library files to include
48-
- gate_defs: Dictionary mapping gate names to their definitions
49-
- gate_refs: List of available gate names for validation
50-
- program: Accumulated program code with proper indentation
51-
- scope: Current nesting level for proper code formatting
48+
49+
- imports: List of library files to include
50+
- gate_defs: Dictionary mapping gate names to their definitions
51+
- gate_refs: List of available gate names for validation
52+
- program: Accumulated program code with proper indentation
53+
- scope: Current nesting level for proper code formatting
5254
"""
5355

5456
def __init__(self):
5557
"""
5658
Initialize the base file builder with empty data structures.
5759
5860
Sets up the foundational components needed for code generation:
59-
- Empty import list for library dependencies
60-
- Empty gate definitions dictionary for custom gates
61-
- Empty gate references list for scope validation
62-
- Empty program string for accumulating generated code
63-
- Zero scope level for proper indentation tracking
61+
62+
- Empty import list for library dependencies
63+
- Empty gate definitions dictionary for custom gates
64+
- Empty gate references list for scope validation
65+
- Empty program string for accumulating generated code
66+
- Zero scope level for proper indentation tracking
6467
"""
6568
self.imports = [] # List of library names to import (e.g., "std_gates.inc")
6669
self.gate_defs = {} # Dictionary mapping gate names to definition strings
@@ -125,9 +128,10 @@ class GateBuilder(FileBuilder):
125128
complete circuit structure.
126129
127130
Use cases:
128-
- Creating custom gate libraries
129-
- Generating reusable quantum subroutines
130-
- Building modular quantum components
131+
132+
- Creating custom gate libraries
133+
- Generating reusable quantum subroutines
134+
- Building modular quantum components
131135
"""
132136

133137
def import_library(self, lib_class, annotated=False):
@@ -168,12 +172,13 @@ class QasmBuilder(FileBuilder):
168172
resource allocation and generates standards-compliant OpenQASM code.
169173
170174
Features:
171-
- Automatic OpenQASM version header generation
172-
- Qubit and classical bit resource management
173-
- Dynamic resource allocation with claim methods
174-
- Complete circuit structure generation
175-
- Library import management
176-
- Gate definition embedding
175+
176+
- Automatic OpenQASM version header generation
177+
- Qubit and classical bit resource management
178+
- Dynamic resource allocation with claim methods
179+
- Complete circuit structure generation
180+
- Library import management
181+
- Gate definition embedding
177182
"""
178183

179184
def __init__(self, qubits, clbits=None, version=3):
@@ -256,11 +261,12 @@ def build(self):
256261
Generate the complete OpenQASM circuit code.
257262
258263
Assembles all components into a valid OpenQASM program including:
259-
1. Version header (OPENQASM 3;)
260-
2. Include statements for imported libraries
261-
3. Qubit and classical bit declarations
262-
4. Custom gate definitions
263-
5. Main program code
264+
265+
1. Version header (OPENQASM 3;)
266+
2. Include statements for imported libraries
267+
3. Qubit and classical bit declarations
268+
4. Custom gate definitions
269+
5. Main program code
264270
265271
Returns:
266272
str: Complete OpenQASM program ready for execution
@@ -319,10 +325,11 @@ class IncludeBuilder(FileBuilder):
319325
subroutines but do not include qubit declarations or main program logic.
320326
321327
Include files are useful for:
322-
- Sharing gate definitions across multiple circuits
323-
- Creating domain-specific gate libraries
324-
- Modular quantum program development
325-
- Standardizing common quantum operations
328+
329+
- Sharing gate definitions across multiple circuits
330+
- Creating domain-specific gate libraries
331+
- Modular quantum program development
332+
- Standardizing common quantum operations
326333
"""
327334

328335
def build(self):

0 commit comments

Comments
 (0)