Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add quick start questions #375

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
BitBasis = "50ba71b6-fa0f-514d-ae9a-0916efc90dcf"
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
DocThemeIndigo = "8bac0ac5-51bf-41f9-885e-2bf1ac2bec5f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
Expand All @@ -14,4 +15,6 @@ Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"
YaoAPI = "0843a435-28de-4971-9e8b-a9641b2983a8"
YaoArrayRegister = "e600142f-9330-5003-8abb-0ebd767abc51"
YaoBlocks = "418bc28f-b43b-5e0b-a6e7-61bbc1a2c1df"
YaoPlots = "32cfe2d9-419e-45f2-8191-2267705d8dbc"
YaoSym = "3b27209a-d3d6-11e9-3c0f-41eb92b2cb9d"
ZXCalculus = "3525faa3-032d-4235-a8d4-8c2939a218dd"
95 changes: 94 additions & 1 deletion docs/src/quick-start.md
Original file line number Diff line number Diff line change
@@ -1 +1,94 @@
# Quick Start
# Quick Start

In this quick start, we list several common use cases for Yao before you
go deeper into the manual.

## Create a quantum register/state

A register is an object that describes a device with an internal state. See [Registers](@ref registers)
for more details. Yao use registers to represent quantum states. The most common register
is the [`ArrayReg`](@ref), you can create it by feeding a state vector to it, e.g

```@repl quick-start
using Yao
ArrayReg(rand(ComplexF64, 2^3))
zero_state(5)
rand_state(5)
product_state(bit"10100")
ghz_state(5)
```

the internal quantum state can be accessed via [`statevec`](@ref) method

```@repl quick-start
statevec(ghz_state(2))
```

for more functionalities about registers please refer to the manual of [`registers`](@ref).

## Create quantum circuit with Yao blocks

Yao uses the quantum "block"s to describe quantum circuits, e.g
the following code creates a 2-qubit circuit

```@repl quick-start
chain(2, put(1=>H), put(2=>X))
```

where `H` gate is at 1st qubit, `X` gate is at 2nd qubit.
A more advanced example is the quantum Fourier transform circuit

```@repl quick-start
A(i, j) = control(i, j=>shift(2π/(1<<(i-j+1))))
B(n, k) = chain(n, j==k ? put(k=>H) : A(j, k) for j in k:n)
qft(n) = chain(B(n, k) for k in 1:n)
qft(3)
```

## Create Hamiltonian with Yao blocks

the quantum "block"s are expressions on quantum operators, thus, it can
also be used to represent a Hamiltonian, e.g we can create a simple Ising
Hamiltonian on 1D chain as following

```@repl quick-start
sum(kron(5, i=>Z, mod1(i+1, 5)=>Z) for i in 1:5)
```

## Automatic differentiate a Yao block

Yao has its own automatic differentiation rule implemented, this allows one obtain
gradients of a loss function by simply putting a `'` mark behind [`expect`](@ref)
or [`fidelity`](@ref), e.g

```@repl quick-start
expect'(X, zero_state(1)=>Rx(0.2))
```

or for fiedlity

```@repl quick-start
fidelity'(zero_state(1)=>Rx(0.1), zero_state(1)=>Rx(0.2))
```

## Combine Yao with ChainRules/Zygote


## Symbolic calculation with Yao block
Yao supports symbolic calculation of quantum circuit via `SymEngine`. We can show


## Plot quantum circuits

The [YaoPlots]() in Yao's ecosystem provides plotting for quantum circuits and ZX diagrams.

```@example quick-start
using Yao.EasyBuild, YaoPlots
using Compose

# show a qft circuit
Compose.SVG(plot(qft_circuit(5)))
```

## Convert quantum circuits to tensor network
## Simplify quantum circuit with ZX calculus