SnowflurrySDK / Snowflurry.jl

Snowflurry is an open source Julia-based software library for implementing quantum circuits, and then running them on quantum computers and quantum simulators. The project is sponsored by Anyon Systems, Inc. See https://snowflurrySDK.github.io/Snowflurry.jl/dev for the latest documentation.
https://snowflurry.dev
Apache License 2.0
48 stars 6 forks source link
julia julia-language julia-package julialang quantum quantum-algorithms quantum-computing quantum-mechanics

Snowflurry

Snowflurry.jl

CI tests codecov

Snowflurry is an open source Julia-based software library for implementing quantum circuits, and then running them on quantum computers and quantum simulators.

Installation

The following installation steps are for people interested in using Snowflurry in their own applications. If you are interested in contributing, head right over to our Contributing to Snowflurry page.

Installing Julia

Make sure your system has Julia installed. If not, download the latest version from https://julialang.org/downloads/.

We officially support the latest stable release and the latest Long-Term Support (LTS) release. Any release in between should work (please submit a Github issue if they don't), but we only actively test against the LTS and the latest stable version.

Installing Snowflurry.jl

The latest release of Snowflurry can be pulled from JuliaHub and installed with the following command:

import Pkg
Pkg.add("Snowflurry")

This adds the Snowflurry package to the current Julia Environment.

Snowflurry is under active development. To use the development version, the main branch from Github can be installed instead using the following commands in the Julia REPL:

import Pkg
Pkg.add(url="https://github.com/SnowflurrySDK/Snowflurry.jl", rev="main")

Warning: The main branch of Snowflurry targets new internal infrastructure. Existing users should use the latest stable release instead.

Installing SnowflurryPlots.jl

Multiple visualization tools are available in the SnowflurryPlots package. After installing Snowflurry, the SnowflurryPlots package can be installed by entering the following in the Julia REPL:

import Pkg
Pkg.add(url="https://github.com/SnowflurrySDK/SnowflurryPlots.jl", rev="main")

Getting Started

The best way to learn Snowflurry is to use it! Let's try to make a two-qubit circuit which produces a Bell/EPR state. We'll use Snowflurry to construct and simulate the circuit, then we'll verify the produced Ket.

The quantum circuit for generating a Bell state involves a Hadamard gate on one of the qubits followed by a CNOT gate (see here for an introduction to quantum logic gates). This circuit is shown below:

First, we'll import Snowflurry:

using Snowflurry

We can then define our two-qubit circuit:

c = QuantumCircuit(qubit_count = 2)
print(c)

# output
Quantum Circuit Object:
   qubit_count: 2
   bit_count: 2
q[1]:

q[2]:

In Snowflurry, all qubits start in state $\left|0\right\rangle$. Our circuit is, therefore, in state $\left|00\right\rangle$. The qubit ordering convention used is qubit number 1 on the left, with each following qubit to the right of it. We now proceed by adding gates to our circuit:

push!(c, hadamard(1))
push!(c, control_x(1, 2))

print(c)

# output
Quantum Circuit Object:
   qubit_count: 2
   bit_count: 2
q[1]:──H────*──
            |
q[2]:───────X──

The first line adds a Hadamard gate to circuit object c. The Hadamard gate operates on qubit 1. The second line adds a CNOT gate (controlled-X gate) with qubit 1 as the control qubit and qubit 2 as the target qubit.

Note: Unlike C++ or Python, indexing in Julia starts from "1" and not "0"!

It might be helpful to transpile our circuit after building it. Transpilation is a process that replaces the operations in our circuit by an equivalent sequence of operations. This new sequence will produce the same quantum state. However, the new sequence may be optimized for performance and only use gates which are supported by a specific quantum processor. We won't transpile the circuit in our example since it is relatively small and the simulator in Snowflurry can handle every gate.

Next, we'll simulate our circuit to see if we've built what we expect:

ψ = simulate(c)
print(ψ)

# output
4-element Ket{ComplexF64}:
0.7071067811865475 + 0.0im
0.0 + 0.0im
0.0 + 0.0im
0.7071067811865475 + 0.0im

Some of you may have recognized that the resultant state is the Bell state, an equal superposition of the $\left|00\right\rangle$ and $\left|11\right\rangle$ states.

Finally, we can use SnowflurryPlots to generate a histogram that shows the measurement output distribution for our Bell state:

using SnowflurryPlots
plot_histogram(c, 100)

We specified that the quantum computer simulator had to take 100 shots (i.e. measurements) to create the distribution.

The following script combines all the previous steps:

using Snowflurry, SnowflurryPlots
c = QuantumCircuit(qubit_count = 2)
push!(c, hadamard(1))
push!(c, control_x(1, 2))
ψ = simulate(c)
plot_histogram(c, 100)

You can learn how to execute circuits on simulated hardware by following the Virtual QPU tutorial.

For selected partners and users who have been granted access to Anyon's hardware, follow the Virtual QPU tutorial first, then check out how to run circuits on real hardware.

Roadmap

See what we have planned by looking at the Snowflurry Github Project.

Snowflurry Contributors Community

We welcome contributions! If you are interested in contributing to this project, a good place to start is to read our How to Contribute page.

We are dedicated to cultivating an open and inclusive community to build software for near-term quantum computers. Please read our Code of Conduct for the rules of engagement within our community.

Alpha Disclaimer

Snowflurry is currently in alpha. We may change or remove parts of Snowflurry's API when making new releases.

Copyright (c) 2023 by Snowflurry Developers and Anyon Systems, Inc.