Skip to content

Commit c96f3f7

Browse files
qBraid Algos v0.1 (#56)
* initial commit - created first qasm file * bells inequality .qasm file update * bells inequality qasm * bern-vaz example ('1001') * load .qasm w/ pyqasm * fix * prelim autoqasm bern-vaz - needs sdk integration * pqasm loading fix * Update CONTRIBUTING.md fixed coverage report test * simple bells inequality circuit example, cleaned up * testing for bell's inequality qasm3 circuits * fix init docs & update measurement from qasm2 to qasm3 * change load_circuit to load_program, create simple jupyter notebook example for Bell's * initial BernVaz implementation - needs autoqasm_to_qasm3 * autoqasm -> qasm3 integration * testing * preliminary commit - starting to implement bernvaz and QFT - not complete / ready for review yet (needs testing) * fixed QFT function * Cleaned up QFT/IQFT - still beta version * refactoring -> use static qasm + dynamic .inc instead of autoqasm * refactor and cleanup of qft/iqft - still needs tests * refactoring workflow - QFT complete * iqft refactor * move input logic to seperate function * Basic implementation of BernVaz, QFT, IQFT complete, along with simple bells inequality example circuit. load_program and load_subroutine available for these. * cleanup, basic tests, basic CLI implementation * custom path handling + output silencing for circuit generation functions (python & cli) * Basic QPE implementation * docs * Added samples of running programs to example notebooks * cleanup, testing, documentation - getting close to ready for release * remove Bells Inequality (no clear purpose), add BernVaz testing/updates to Bernvaz example notebook * formatting fixes * import sorting * Fixes to v0.1 dev (#58) * format / structure updates * fix mypy + test deps * add missing qpe.qasm file * CLI tests, codecov * cli test fixes * cleanup, fixed CLI testing format * testing reqs --------- Co-authored-by: Ryan Hill <ryanjh88@gmail.com>
1 parent d7bad30 commit c96f3f7

66 files changed

Lines changed: 4897 additions & 258 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 144 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,150 @@ import qbraid_algorithms
5757
qbraid_algorithms.__version__
5858
```
5959

60+
## Key Features: Load algorithms as PyQASM modules and QASM files
61+
62+
qBraid Algorithms provides a collection of quantum algorithms that can be loaded
63+
as [PyQASM](https://docs.qbraid.com/pyqasm/user-guide/overview) modules, or
64+
you can generate .qasm files to use them as subroutines in your own circuits.
65+
66+
### Loading Algorithms as PyQASM Modules
67+
68+
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:
69+
70+
```python
71+
from qbraid_algorithms import qft
72+
73+
qft_module = qft.load_algorithm(3) # Load QFT for 3 qubits
74+
```
75+
76+
Now, you can perform operations with the PyQASM module, such as unrolling, and
77+
converting back to a QASM string:
78+
79+
```python
80+
qft_module.unroll()
81+
qasm_str = pyqasm.dumps(qft_module)
82+
```
83+
84+
### Loading Algorithms as `.qasm` Files
85+
86+
In order to utilize algorithms as subroutines in your own circuits, use the
87+
`generate_subroutine` function for your desired algorithm. By passing algorithm-specific parameters, and optionally a desired output path, you can
88+
generate a .qasm file containing a subroutine for the paramterized circuit. For
89+
example, to generate a QFT subroutine for 4 qubits:
90+
91+
```python
92+
from qbraid_algorithms import qft, iqft
93+
path = "path/to/output" # Specify your desired output path
94+
qft.generate_subroutine(4) # Generate 4-qubit QFT in the current directory
95+
iqft.generate_subroutine(4, path=path) # Generate 4-qubit IQFT in specified path
96+
97+
```
98+
99+
To utilize the generated subroutine in your own circuit, include the generated
100+
.qasm file, and call the subroutine on an qubit register of the size specified
101+
when generating the subroutine. For example, after running
102+
103+
```python
104+
qft.generate_subroutine(4)
105+
```
106+
107+
you can append `include "qft.qasm";` to your OpenQASM file, and call the
108+
subroutine. For example:
109+
110+
```qasm
111+
OPENQASM 3.0;
112+
include "qft.qasm";
113+
114+
qubit[4] q;
115+
bit[4] c;
116+
117+
qft(q);
118+
measure q -> c;
119+
```
120+
121+
## CLI Usage
122+
123+
qBraid Algorithms includes a command-line interface (CLI) for generating quantum algorithm subroutines.
124+
125+
### Installation
126+
127+
To use the CLI, install with CLI dependencies:
128+
129+
```bash
130+
pip install "qbraid-algorithms[cli]"
131+
```
132+
133+
Or install from source:
134+
135+
```bash
136+
pip install -e ".[cli]"
137+
```
138+
139+
### Generate Subroutines
140+
141+
Generate quantum algorithm subroutines that can be included in other circuits:
142+
143+
```bash
144+
# Generate QFT subroutine for 4 qubits
145+
qbraid-algorithms generate qft --qubits 4
146+
147+
# Generate IQFT subroutine for 3 qubits with custom name and show the circuit
148+
qbraid-algorithms generate iqft -q 3 -o my_iqft.qasm --gate-name my_iqft --show
149+
150+
# Generate Bernstein-Vazirani circuit for secret "101" and display it
151+
qbraid-algorithms generate bernvaz --secret "101" --show
152+
153+
# Generate only the oracle for Bernstein-Vazirani
154+
qbraid-algorithms generate bernvaz -s "1001" --oracle-only --show
155+
156+
# Generate QPE subroutine for 4 qubits with a custom unitary gate
157+
qbraid-algorithms generate qpe --unitary-file my_gate.qasm --qubits 4
158+
159+
# Generate QPE with custom output and show the circuit
160+
qbraid-algorithms generate qpe -u gate.qasm -q 3 -o my_qpe.qasm --show
161+
```
162+
163+
### Help
164+
165+
Get help for any command:
166+
167+
```bash
168+
qbraid-algorithms --help
169+
qbraid-algorithms generate --help
170+
qbraid-algorithms generate qft --help
171+
qbraid-algorithms generate iqft --help
172+
qbraid-algorithms generate bernvaz --help
173+
qbraid-algorithms generate qpe --help
174+
qbraid-algorithms generate bernvaz --help
175+
```
176+
177+
### Examples
178+
179+
#### Complete Workflow
180+
181+
1. Generate a QFT subroutine:
182+
183+
```bash
184+
qbraid-algorithms generate qft --qubits 3
185+
```
186+
187+
2. Generate a Bernstein-Vazirani oracle and view it:
188+
189+
```bash
190+
qbraid-algorithms generate bernvaz --secret "101" --oracle-only --show
191+
```
192+
193+
3. Generate an IQFT circuit with custom output:
194+
195+
```bash
196+
qbraid-algorithms generate iqft --qubits 4 --output my_iqft_4.qasm --show
197+
```
198+
199+
4. Generate a QPE subroutine for phase estimation:
200+
```bash
201+
qbraid-algorithms generate qpe --unitary-file t_gate.qasm --qubits 3 --show
202+
```
203+
60204
## Community
61205

62206
**We are actively looking for new contributors!**
@@ -68,12 +212,6 @@ qbraid_algorithms.__version__
68212
- For questions that are more suited for a forum, post to [Stack Exchange](https://quantumcomputing.stackexchange.com/) with the [`qbraid`](https://quantumcomputing.stackexchange.com/questions/tagged/qbraid) tag.
69213
- By participating, you are expected to uphold our [code of conduct](CODE_OF_CONDUCT).
70214

71-
## Acknowledgements
72-
73-
This project was conceived in cooperation with the Quantum Open Source Foundation ([QOSF](https://qosf.org/)).
74-
75-
<a href="https://qosf.org/"><img src="https://qbraid-static.s3.amazonaws.com/logos/qosf.png" width="100px" style="vertical-align: middle;" /></a>
76-
77215
## License
78216

79217
[Apache-2.0 License](LICENSE)

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Set the version
1616
version = qbraid_algorithms.__version__
17-
17+
release = version
1818
# -- General configuration ---------------------------------------------------
1919

2020
# Add any Sphinx extension module names here, as strings. They can be

docs/index.rst

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<span style="color:#808080"> | algorithms</span>
5252
</h1>
5353
<p style="text-align:center;font-style:italic;color:#808080">
54-
Build hybrid quantum-classical algorithms with qBraid.
54+
Use and build quantum algorithms with qBraid.
5555
</p>
5656
</body>
5757
</html>
@@ -63,7 +63,7 @@
6363
Overview
6464
---------
6565

66-
Python package for building, simulating, and benchmarking hybrid quantum-classical algorithms.
66+
Python package for utilizing, implementing, and building quantum algorithms in OpenQASM 3.
6767

6868

6969
Installation
@@ -91,44 +91,44 @@ You can also install from source by cloning this repository and running a pip in
9191
Resources
9292
----------
9393

94-
- `User Guide <https://docs.qbraid.com/sdk/user-guide>`_
95-
- `Example Notebooks <https://github.com/qBraid/qbraid-lab-demo>`_
96-
- `API Reference <https://qbraid.github.io/qBraid/api/qbraid_algorithms.html>`_
94+
- `User Guide <https://docs.qbraid.com/qbraid-algorithms/user-guide/overview>`_
95+
- `Example Notebooks <https://github.com/qBraid/qbraid-algorithms/tree/main/examples>`_
96+
- `API Reference <https://sdk.qbraid.com/qBraid/api/qbraid_algorithms.html>`_
9797
- `Source Code <https://github.com/qBraid/qbraid-algorithms>`_
9898

9999
.. toctree::
100100
:maxdepth: 1
101101
:caption: SDK API Reference
102102
:hidden:
103103

104-
qbraid <https://qbraid.github.io/qBraid/api/qbraid.html>
105-
qbraid.programs <https://qbraid.github.io/qBraid/api/qbraid.programs.html>
106-
qbraid.interface <https://qbraid.github.io/qBraid/api/qbraid.interface.html>
107-
qbraid.transpiler <https://qbraid.github.io/qBraid/api/qbraid.transpiler.html>
108-
qbraid.passes <https://qbraid.github.io/qBraid/api/qbraid.passes.html>
109-
qbraid.runtime <https://qbraid.github.io/qBraid/api/qbraid.runtime.html>
110-
qbraid.visualization <https://qbraid.github.io/qBraid/api/qbraid.visualization.html>
104+
qbraid <https://sdk.qbraid.com/qBraid/api/qbraid.html>
105+
qbraid.programs <https://sdk.qbraid.com/qBraid/api/qbraid.programs.html>
106+
qbraid.interface <https://sdk.qbraid.com/qBraid/api/qbraid.interface.html>
107+
qbraid.transpiler <https://sdk.qbraid.com/qBraid/api/qbraid.transpiler.html>
108+
qbraid.passes <https://sdk.qbraid.com/qBraid/api/qbraid.passes.html>
109+
qbraid.runtime <https://sdk.qbraid.com/qBraid/api/qbraid.runtime.html>
110+
qbraid.visualization <https://sdk.qbraid.com/qBraid/api/qbraid.visualization.html>
111111

112112
.. toctree::
113113
:caption: QIR API Reference
114114
:hidden:
115115

116-
qbraid_qir <https://qbraid.github.io/qbraid-qir/api/qbraid_qir.html>
117-
qbraid_qir.cirq <https://qbraid.github.io/qbraid-qir/api/qbraid_qir.cirq.html>
118-
qbraid_qir.qasm3 <https://qbraid.github.io/qbraid-qir/api/qbraid_qir.qasm3.html>
116+
qbraid_qir <https://sdk.qbraid.com/qbraid-qir/api/qbraid_qir.html>
117+
qbraid_qir.cirq <https://sdk.qbraid.com/qbraid-qir/api/qbraid_qir.cirq.html>
118+
qbraid_qir.qasm3 <https://sdk.qbraid.com/qbraid-qir/api/qbraid_qir.qasm3.html>
119119

120120
.. toctree::
121121
:caption: CORE API Reference
122122
:hidden:
123123

124-
qbraid_core <https://qbraid.github.io/qbraid-core/api/qbraid_core.html>
125-
qbraid_core.services <https://qbraid.github.io/qbraid-core/api/qbraid_core.services.html>
124+
qbraid_core <https://sdk.qbraid.com/qbraid-core/api/qbraid_core.html>
125+
qbraid_core.services <https://sdk.qbraid.com/qbraid-core/api/qbraid_core.services.html>
126126

127127
.. toctree::
128128
:caption: PYQASM API Reference
129129
:hidden:
130130

131-
pyqasm <https://qbraid.github.io/pyqasm/api/pyqasm.html>
131+
pyqasm <https://sdk.qbraid.com/pyqasm/api/pyqasm.html>
132132

133133

134134
.. toctree::

examples/QPE/prepare_state.qasm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
OPENQASM 3.0;
2+
include "stdgates.inc";
3+
4+
gate prep q {
5+
x q;
6+
}

0 commit comments

Comments
 (0)