Giter Site home page Giter Site logo

qudirac.jl's Introduction

Latest Stable Release (v0.1): Build Status

Upcoming Release (v0.2): Build Status

QuDirac.jl

QuDirac.jl is a Julia library for using Dirac notation to perform quantum mechanics computations.

Documentation for the current release version (v0.1) can be found here.

Installation

To install QuDirac.jl, you should have a working build of Julia v0.3. Then, you can grab QuDirac.jl via the package manager:

julia> Pkg.add("QuDirac")

Features

These are toy examples for demoing features. See below for more involved examples.

Ket, Bra, and Operator types

julia> bell = d" 1/√2 * (| 0,0 > + | 1,1 >) "
Ket{KroneckerDelta,2,Float64} with 2 state(s):
  0.7071067811865475 | 0,00.7071067811865475 | 1,1 ⟩

julia> bell'
Bra{KroneckerDelta,2,Float64} with 2 state(s):
  0.70710678118654750,0 |
  0.70710678118654751,1 |

julia> ptrace(bell * bell', 1)
OpSum{KroneckerDelta,1,Float64} with 2 operator(s):
  0.4999999999999999 | 0 ⟩⟨ 0 |
  0.4999999999999999 | 1 ⟩⟨ 1 |

Support for undefined inner products

# tells QuDirac to use the rule for undefined inner products
julia> default_inner(UndefinedInner())
INFO: QuDirac's default inner product type is currently UndefinedInner()

julia> d" < 0,0 | *  (| 0,0 > + | 1,1 >)/√2 "
((⟨ 0,0 | 0,0+0,0 | 1,1 ⟩) / 1.4142135623730951)

julia> s = d" (e^( < 1,2 | 3,4 > ) + < 5,6 | 7,8 > * im)^4 "
(((exp(⟨ 1,2 | 3,4 ⟩)) + (⟨ 5,6 | 7,8* im))^4)

julia> inner_eval((b, k) -> sum(k) - sum(b), s)
8.600194553751864e6 + 2.5900995362955774e6im

Custom inner product rules

julia> immutable MyInner <: AbstractInner end

julia> QuDirac.inner_rule(::MyInner, ktlabel, brlabel) = sqrt(ktlabel[1]+brlabel[1])
inner_rule (generic function with 3 methods)

julia> default_inner(MyInner())
INFO: QuDirac's default inner product type is currently MyInner()

# eval ⟨ π | e ⟩ with MyInner rule -> sqrt(π + e)
julia> d" < π | e > "
2.420717761749361

Functional operator construction

# define a₂ on Ket
julia> @def_op " a₂ | x, y, z > = √y * | x, y - 1, z > "
a₂ (generic function with 1 method)

# define a₂ on Bra
julia> @def_op " < x, y, z | a₂ = √(y + 1) * < x, y + 1, z | "
a₂ (generic function with 2 methods)

julia> d" a₂ * | 3,5,5 > "
Ket{KroneckerDelta,3,Float64} with 1 state(s):
  2.23606797749979 | 3,4,5 ⟩

julia> d" a₂' * | 3,4,5 > "
Ket{KroneckerDelta,3,Float64} with 1 state(s):
  2.23606797749979 | 3,5,5 ⟩

julia> d" < 3,4,5 | * a₂ * | 3,5,5 > "
2.23606797749979

# Hadamard operator
julia> @rep_op " H | n > = 1/√2 * ( | 0 > + (-1)^n *| 1 > ) " 0:1;

julia> H
OpSum{KroneckerDelta,1,Float64} with 4 operator(s):
  0.7071067811865475 | 1 ⟩⟨ 0 |
  0.7071067811865475 | 0 ⟩⟨ 0 |
  0.7071067811865475 | 0 ⟩⟨ 1 |
  -0.7071067811865475 | 1 ⟩⟨ 1 |

...and other stuff

  • Implementation of common operations like partial trace (ptrace) and partial transpose (ptranspose)
  • Treat states and operators as map-like data structures, enabling label-based analysis for spectroscopy purposes
  • xsubspace allows easy selection of excitation subspaces of states and operators
  • permute and switch allows generic permutation of factor labels for states
  • filter/filter! for the filtering out component states/operators via predicate functions
  • Arbitrary mapping functions (map/maplabels/mapcoeffs) for applying functions to labels and coefficients

Examples

There are currently two example files, qho.jl and randwalk.jl. The former implements methods for plotting quantum harmonic oscillator wave functions using Plotly. The latter is a simple implementation of a quantum random walk.

To run the examples, one can do the following (using qho.jl as an example):

julia> cd(Pkg.dir("QuDirac"))
julia> include("examples/qho.jl")

qudirac.jl's People

Contributors

jrevels avatar d0ugal avatar penify-dev[bot] avatar

Watchers

Robert Bongart (MSc MSc MA) avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.