Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Commit

Permalink
separate export
Browse files Browse the repository at this point in the history
  • Loading branch information
goropikari committed Apr 21, 2018
1 parent c6b26fa commit 06f6556
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 95 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
[![codecov.io](http://codecov.io/github/goropikari/QuantumInformation.jl/coverage.svg?branch=master)](http://codecov.io/github/goropikari/QuantumInformation.jl?branch=master)
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://goropikari.github.io/QuantumInformation.jl/latest/)

This is unofficial extension of [QuantumOptics.jl](https://github.com/qojulia/QuantumOptics.jl).
I imagine those who want to learn quantum computing use this package.
QuantumInformation.jl is a package for learning quantum computation.
I add some functions to [QuantumOptics.jl](https://github.com/qojulia/QuantumOptics.jl).

**Features**
- Add some quantum gates for qubits (spin 1/2)
- You can take complex conjugate transpose (dagger) by single-quote `'`.
- Print Ket, Bra, and Operator by MathJax(ASCIIart) in IJulia(REPL).

**Example**
- [Quantum teleportation](https://nbviewer.jupyter.org/github/goropikari/QuantumInformation.jl/blob/master/examples/quantum_teleportation.ipynb)
Expand All @@ -29,28 +31,30 @@ Pkg.clone("https://github.com/goropikari/QuantumInformation.jl")
# Usage
## Simple example
```julia
julia> ψ = qubit("00")
julia> using QuantumInformation.ShortNames

julia> ψ = qubit("00") # prepare |00⟩ state
Ket(dim=4)
basis: [Spin(1/2) Spin(1/2)]
1.0+0.0im
0.0+0.0im
0.0+0.0im
0.0+0.0im

julia> ϕ = cnot() * (H() id()) * ψ
julia> ϕ = cnot() * (H() id()) * ψ # apply hadamard gate on first qubit and then apply CNOT gate.
Ket(dim=4)
basis: [Spin(1/2) Spin(1/2)]
0.707107+0.0im
0.0+0.0im
0.0+0.0im
0.707107+0.0im

julia> tex(ϕ)
julia> tex(ϕ) # print braket form.
|ψ> = 0.707|00> + 0.707|11>
```

## Quantum gates
Supported quantum gates are following.
Supported quantum gates are as follows.
### Pauli matrix
```julia
julia> sigmax()
Expand Down
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Documenter, QuantumInformation, QuantumInformation.ShortNames
using Documenter, QuantumInformation.ShortNames

makedocs(
format=:html,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ QuantumInformation.sparse_spinalldown_dm
## Quantum Gates

```@docs
QuantumInformation.id
QuantumInformation.ShortNames.id
QuantumInformation.sigmax
QuantumInformation.sigmay
QuantumInformation.sigmaz
Expand Down
15 changes: 8 additions & 7 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ QuantumInformation.jl is a package for learning quantum computation.
I add quantum gates to [QuantumOptics.jl](https://github.com/qojulia/QuantumOptics.jl).

## Installation
Install QuantumInformation.jl within Julia using
```julia
Pkg.clone("https://github.com/goropikari/QuantumInformation.jl")
```

## Basic usage
Make Bell state $| \psi \rangle = \frac{1}{2} (| 00 \rangle + | 11 \rangle)$.
## Getting Started
We start this tutorial with a very simple example that creats a Bell state, $| \psi \rangle = \frac{1}{2} (| 00 \rangle + | 11 \rangle)$.
```julia
julia> using QuantumInformation, QuantumInformation.ShortNames
julia> using QuantumInformation.ShortNames

julia> ψ = qubit("00")
julia> ψ = qubit("00") # prepare |00> state
Ket(dim=4)
basis: [Spin(1/2) Spin(1/2)]
1.0+0.0im
0.0+0.0im
0.0+0.0im
0.0+0.0im

julia> ϕ = cnot() * (H() id()) * ψ
julia> ϕ = cnot() * (H() id()) * ψ # apply hadamard gate on first qubit and then apply CNOT gate.
Ket(dim=4)
basis: [Spin(1/2) Spin(1/2)]
0.707107+0.0im
0.0+0.0im
0.0+0.0im
0.707107+0.0im

julia> tex(ϕ)
|ψ> = 0.707|00> + 0.707|11>
julia> tex(ϕ) # print braket form.
|ψ = 0.707|00 + 0.707|11
```
2 changes: 1 addition & 1 deletion docs/src/latex.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Qubit ( SpinBasis(1//2) ) state can be rendered by MathJax(ASCII art) on IJulia(REPL).
```julia
cnot() * (H() id()) * qubit("00")
cnot() * (H() id()) * qubit("00") |> tex
```

**IJulia**
Expand Down
14 changes: 2 additions & 12 deletions examples/latex.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: using QuantumInformation.eval in module Main conflicts with an existing identifier.\n"
]
}
],
"outputs": [],
"source": [
"# using Revise\n",
"using QuantumInformation\n",
"using QuantumInformation.ShortNames"
]
},
Expand Down Expand Up @@ -84,7 +74,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down
63 changes: 36 additions & 27 deletions examples/quantum_teleportation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 1,
"metadata": {
"run_control": {
"marked": false
}
},
"outputs": [],
"source": [
"# using Revise\n",
"using QuantumInformation"
"using QuantumInformation.ShortNames"
]
},
{
Expand All @@ -32,9 +31,16 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Initial state\n"
]
},
{
"data": {
"text/latex": [
Expand All @@ -48,29 +54,26 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Initial state\n",
"ψ = α * spinup(basis) + β * spindown(basis) = Ket(dim=2)\n",
"ψ = α * qubit(\"0\") + β * qubit(\"1\") = Ket(dim=2)\n",
" basis: Spin(1/2)\n",
" 0.5+0.0im\n",
" 0.866025+0.0im\n"
]
}
],
"source": [
"basis = SpinBasis(1//2)\n",
"θ = π / 3 \n",
"α, β = cos(θ), sin(θ)\n",
"id = identityoperator(basis)\n",
"\n",
"println(\"Initial state\")\n",
"@show ψ = α * spinup(basis) + β * spindown(basis)\n",
"state = ψ ⊗ spinup(basis) ⊗ spinup(basis)\n",
"@show ψ = α * qubit(\"0\") + β * qubit(\"1\")\n",
"state = ψ ⊗ qubit(\"00\")\n",
"state |> tex"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -84,13 +87,13 @@
}
],
"source": [
"state = (id ⊗ hadamard() ⊗ id) * state\n",
"state = (id()H() ⊗ id()) * state\n",
"state |> tex"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -104,13 +107,13 @@
}
],
"source": [
"state = (id ⊗ cnot()) * state\n",
"state = (id() ⊗ cnot()) * state\n",
"state |> tex"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -124,13 +127,13 @@
}
],
"source": [
"state = (cnot() ⊗ id) * state\n",
"state = (cnot() ⊗ id()) * state\n",
"state |> tex"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand All @@ -144,13 +147,13 @@
}
],
"source": [
"state = (hadamard() ⊗ id ⊗ id) * state\n",
"state = (H() ⊗ id(2)) * state\n",
"state |> tex"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand All @@ -170,7 +173,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -190,9 +193,17 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Before applying X and Z gates\n"
]
},
{
"data": {
"text/latex": [
Expand All @@ -206,8 +217,6 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Before applying X and Z gates\n",
"finstate = DenseOperator(dim=2x2)\n",
" basis: Spin(1/2)\n",
" 0.75+0.0im 0.433013+0.0im\n",
Expand All @@ -225,7 +234,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -262,7 +271,7 @@
}
],
"source": [
"finstate = sigmaz()^outcome1 * sigmax()^outcome2 * finstate * sigmax()^outcome2 * sigmaz()^outcome1\n",
"finstate = Z()^outcome1 * X()^outcome2 * finstate * X()^outcome2 * Z()^outcome1\n",
"\n",
"println(\"\\nMeasurement outcome\")\n",
"@show outcome1, outcome2\n",
Expand All @@ -274,12 +283,12 @@
"@show finstate\n",
"finstate |> tex\n",
"\n",
"println(\"\\nCan we teleport quantum state?: \", dm(ψ).data ≈ finstate.data)"
"println(\"\\nCan we teleport quantum state?: \", dm(ψ) ≈ finstate)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down
32 changes: 6 additions & 26 deletions src/QuantumInformation.jl
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
__precompile__()

module QuantumInformation

# package code goes here
using QuantumOptics
import QuantumOptics: sigmam, sigmap, sigmax, sigmay, sigmaz
export Basis , basis , logarithmic_negativity , potentialoperator , spre,
Bra , basisstate , manybody , printing , states,
CompositeBasis , bosonstates , manybodyoperator , projector , steadystate,
DenseOperator , coherentstate , metrics , ptrace , stochastic,
DenseSuperOperator , create , momentum , ptranspose , subspace,
FockBasis , dagger , negativity , qfunc , superoperators,
GenericBasis , destroy , nlevel , random , tensor,
Ket , diagonaljumps , nlevelstate , randoperator , timecorrelations,
LazyProduct , diagonaloperator , normalize , randstate , timeevolution,
LazySum , displace , normalize! , samplepoints , tracedistance,
LazyTensor , dm , number , semiclassical , tracedistance_h,
ManyBodyBasis , eigenenergies , occupation , sigmam , tracedistance_nh,
MomentumBasis , eigenstates , onebodyexpect , sigmap , tracenorm,
NLevelBasis , embed , operators , sigmax , tracenorm_h,
Operator , entropy_vn , operators_dense , sigmay , tracenorm_nh,
PPT , eval , operators_lazyproduct , sigmaz , transform,
PositionBasis , expect , operators_lazysum , simdiag , transformations,
SparseOperator , fermionstates , operators_lazytensor , sortedindices , transition,
SparseSuperOperator , fidelity , operators_sparse , sparsematrix , variance,
SpinBasis , fock , particle , spectralanalysis , wigner,
StateVector , fockstate , permutesystems , spin , ,
SubspaceBasis , gaussianstate , phasespace , spindown,
SuperOperator , identityoperator , polynomials , spinup,
bases , liouvillian , position , spost

include("export.jl")

QuantumOptics.set_printing(standard_order=true)
# The reasons why the order of tensor product is inverted.
Expand All @@ -38,9 +16,11 @@ include("basic.jl")
include("gates.jl")
include("printing.jl")


# Alternative Interface (`using QuantumInformation.ShortNames`)
module ShortNames
using ..QuantumInformation
include("export.jl")
include("shortnames.jl")
end # ShortNames
using .ShortNames
end # module

0 comments on commit 06f6556

Please sign in to comment.