-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beb9c3d
commit 9d27e63
Showing
17 changed files
with
3,832 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: ['*'] | ||
pull_request: | ||
workflow_dispatch: | ||
concurrency: | ||
# Skip intermediate builds: always. | ||
# Cancel intermediate builds: only if it is a pull request build. | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} | ||
jobs: | ||
test: | ||
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} | ||
runs-on: ${{ matrix.os }} | ||
timeout-minutes: 10 | ||
permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created | ||
actions: write | ||
contents: read | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: | ||
- '1' | ||
- 'lts' | ||
- 'pre' | ||
os: | ||
- ubuntu-latest | ||
arch: | ||
- x64 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: julia-actions/setup-julia@v2 | ||
with: | ||
version: ${{ matrix.version }} | ||
arch: ${{ matrix.arch }} | ||
- uses: julia-actions/cache@v2 | ||
- uses: julia-actions/julia-buildpkg@v1 | ||
- uses: julia-actions/julia-runtest@v1 | ||
- uses: julia-actions/julia-processcoverage@v1 | ||
- uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: lcov.info | ||
docs: | ||
name: Documentation | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: write # needed to allow julia-actions/cache to proactively delete old caches that it has created | ||
contents: write | ||
statuses: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: julia-actions/setup-julia@v2 | ||
with: | ||
version: '1' | ||
- uses: julia-actions/cache@v2 | ||
- uses: julia-actions/julia-buildpkg@v1 # forces PkgServer refresh | ||
- name: Configure doc environment | ||
shell: julia --project=docs --color=yes {0} | ||
run: | | ||
using Pkg | ||
Pkg.Registry.update() | ||
Pkg.develop(PackageSpec(path=pwd())) | ||
Pkg.instantiate() | ||
- uses: julia-actions/julia-buildpkg@v1 | ||
- uses: julia-actions/julia-docdeploy@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Run doctests | ||
shell: julia --project=docs --color=yes {0} | ||
run: | | ||
using Documenter: DocMeta, doctest | ||
using Quasar | ||
DocMeta.setdocmeta!(Quasar, :DocTestSetup, :(using Quasar); recursive=true) | ||
doctest(Quasar) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: CompatHelper | ||
on: | ||
schedule: | ||
- cron: 0 0 * * * | ||
workflow_dispatch: | ||
jobs: | ||
CompatHelper: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Pkg.add("CompatHelper") | ||
run: julia -e 'using Pkg; Pkg.add("CompatHelper")' | ||
- name: CompatHelper.main() | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} | ||
run: julia -e 'using CompatHelper; CompatHelper.main()' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Documentation | ||
|
||
on: | ||
push: | ||
branches: | ||
- main # update to match your development branch (master, main, dev, trunk, ...) | ||
tags: '*' | ||
|
||
jobs: | ||
build: | ||
permissions: | ||
contents: write | ||
statuses: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: julia-actions/setup-julia@v2 | ||
with: | ||
version: '1' | ||
- name: Install dependencies | ||
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' | ||
- name: Build and deploy | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: julia --project=docs/ docs/make.jl | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: TagBot | ||
on: | ||
issue_comment: | ||
types: | ||
- created | ||
workflow_dispatch: | ||
inputs: | ||
lookback: | ||
default: "3" | ||
permissions: | ||
actions: read | ||
checks: read | ||
contents: write | ||
deployments: read | ||
issues: read | ||
discussions: read | ||
packages: read | ||
pages: read | ||
pull-requests: read | ||
repository-projects: read | ||
security-events: read | ||
statuses: read | ||
jobs: | ||
TagBot: | ||
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: JuliaRegistries/TagBot@v1 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
ssh: ${{ secrets.DOCUMENTER_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*Manifest.toml | ||
lcov.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Katharine Hyatt <[email protected]> and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name = "Quasar" | ||
uuid = "86e06105-936e-439e-acf0-7687560b0bd9" | ||
authors = ["Katharine Hyatt <[email protected]> and contributors"] | ||
version = "0.0.1" | ||
|
||
[deps] | ||
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" | ||
Automa = "67c07d97-cdcb-5c2c-af73-a7f9c32a568b" | ||
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" | ||
|
||
[compat] | ||
AbstractTrees = "0.4.5" | ||
Aqua = "0.8" | ||
Automa = "1.0.4" | ||
DataStructures = "0.18.20" | ||
Dates = "1" | ||
LinearAlgebra = "1" | ||
PrecompileTools = "1.2.1" | ||
Statistics = "1" | ||
Test = "1" | ||
julia = "1.6" | ||
|
||
[extras] | ||
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test", "Aqua", "Dates", "LinearAlgebra", "Statistics"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Quasar | ||
|
||
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://kshyatt-aws.github.io/Quasar.jl/stable) | ||
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://kshyatt-aws.github.io/Quasar.jl/dev) | ||
[![Build Status](https://github.com/kshyatt-aws/Quasar.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/kshyatt-aws/Quasar.jl/actions/workflows/CI.yml?query=branch%3Amain) | ||
[![codecov](https://codecov.io/gh/kshyatt-aws/Quasar.jl/graph/badge.svg?token=LP1993TMXD)](https://codecov.io/gh/kshyatt-aws/Quasar.jl) | ||
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) | ||
|
||
`Quasar.jl`, the Qu(antum) as(sembly) (lex/pars)er, is a package for lexing and parsing the [OpenQASM quantum assembly IR](https://openqasm.com/). | ||
|
||
`Quasar.jl` works in a two-step fashion: first, it uses a tokenizer to generate an [abstract syntax tree (AST)](https://en.wikipedia.org/wiki/Abstract_syntax_tree) representing the | ||
quantum program, which is a nested structure of `QasmExpression`s. | ||
Then, it walks (visits) the AST to evaluate all loops, conditionals, gate calls, and variable declarations. | ||
|
||
`Quasar` has support for: | ||
|
||
- Basic builtin OpenQASM 3 gates `gphase` and `U` | ||
- Custom gate definitions | ||
- `for` and `while` loops | ||
- `if`, `else`, and `switch` conditional statements | ||
- Builtin OpenQASM3 functions | ||
- Function definitions and calls | ||
- Casting classical types | ||
- Timing statements `barrier` and `delay` | ||
- Pragmas (see below) | ||
|
||
What is *not* yet supported: | ||
- `angle` types | ||
- Annotations | ||
- OpenPulse | ||
|
||
If you need any of these features, feel free to open an issue requesting support for them! | ||
|
||
## Quick Start | ||
|
||
For more extensive examples, see the tests in `test/`. Here, we can parse and visit a simple OpenQASM 3.0 program to generate a Bell circuit: | ||
|
||
```julia | ||
qasm = """OPENQASM 3.0; | ||
gate h a { U(π/2, 0, π) a; gphase(-π/4);}; | ||
gate x a { U(π, 0, π) a; gphase(-π/2);}; | ||
gate cx a, b { ctrl @ x a, b; }; | ||
def bell(qubit q0, qubit q1) { | ||
h q0; | ||
cx q0, q1; | ||
} | ||
qubit[2] q; | ||
bell(q[0], q[1]); | ||
bit[2] b = "00"; | ||
b[0] = measure q[0]; | ||
b[1] = measure q[1]; | ||
""" | ||
|
||
parsed = Quasar.parse_qasm(qasm) | ||
visitor = Quasar.QasmProgramVisitor() | ||
visitor(parsed) | ||
``` | ||
|
||
You can supply [inputs](https://openqasm.com/language/directives.html#input-output) to your program | ||
by creating the `QasmProgramVisitor` with a `Dict{String, Any}` containing the names of the input variables | ||
as the keys and their values as the `Dict`'s values. This allows you to re-use the same AST multiple times | ||
for different inputs. | ||
|
||
Once the visitor has walked the AST, its `instructions` field contains `CircuitInstruction` `NamedTuple`s you can | ||
use to construct your own circuit instruction types. These tuples have fields: | ||
|
||
- `type::String` - the name of the instruction, e.g. `"measure"` or `"cx"` | ||
- `arguments` - any arguments the instruction accepts, such as an angle for an `rx` gate or a `Period` for a `duration` | ||
- `targets::Vector{Int}` - the qubits targeted by this instruction. This should include any control qubits. | ||
- `controls::Vector{Pair{Int,Int}}` - any controls (including `negctrl`) applied to the instruction. The first item in the pair is the qubit, the second is the value controlled upon, so that `2=>0` represents a `negctrl` on qubit 2. | ||
- `exponent::Float64` - the `pow` modifier applied to the instruction, if any | ||
|
||
You can use a package such as [`StructTypes.jl`](https://github.com/JuliaData/StructTypes.jl) to build your circuits and programs from these named tuples. | ||
|
||
In the above example, the `h`, `x`, and `cx` were defined in terms of the built-in gates `U` and `gphase`. In many cases, you may have an implementation of these | ||
gates that is simpler or more efficient. In that case, you can supply your own gate definition file using the [`include` instruction](https://openqasm.com/language/comments.html#included-files), or provide a *function* to generate a dictionary of builtin gates to `Quasar.jl`: | ||
|
||
```julia | ||
using Quasar | ||
|
||
function my_builtin_generator() | ||
... | ||
end | ||
|
||
Quasar.builtin_gates[] = my_builtin_generator | ||
``` | ||
|
||
A generator function is used here in order to allow visitors to overwrite builtin functions in certain scopes without corrupting the reference definition. If you're writing a package which uses Quasar, the `Quasar.builtin_gates[] = my_builtin_generator` should be placed in your main module's `__init__` function. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[deps] | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
Quasar = "86e06105-936e-439e-acf0-7687560b0bd9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Quasar | ||
using Documenter | ||
|
||
DocMeta.setdocmeta!(Quasar, :DocTestSetup, :(using Quasar; recursive=true)) | ||
|
||
makedocs(; | ||
modules=[Quasar], | ||
sitename="Quasar.jl", | ||
repo="github.com/kshyatt-aws/Quasar.jl", | ||
format=Documenter.HTML(; | ||
canonical="github.com/kshyatt-aws/Quasar.jl", | ||
edit_link="main", | ||
assets=String[], | ||
), | ||
pages=[ | ||
"Home" => "index.md", | ||
], | ||
) | ||
|
||
deploydocs(; | ||
repo="github.com/kshyatt-aws/Quasar.jl", | ||
devbranch="main", | ||
) |
Oops, something went wrong.
9d27e63
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
9d27e63
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/117277
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: