Skip to content

Commit

Permalink
First commit (move code from ITensors.jl) (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Jan 19, 2025
1 parent 7da3e9f commit f11870e
Show file tree
Hide file tree
Showing 20 changed files with 2,576 additions and 8 deletions.
8 changes: 8 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ uuid = "fd9b415b-e710-4e2a-b407-cba023081494"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.1.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
ITensorBase = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[compat]
ChainRulesCore = "1.25.1"
ITensorBase = "0.1.8"
LinearAlgebra = "1.10"
julia = "1.10"
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,45 @@ julia> Pkg.add("ITensorQuantumOperatorDefinitions")
## Examples

````julia
using ITensorQuantumOperatorDefinitions: ITensorQuantumOperatorDefinitions
using ITensorBase: ITensor, Index, tags
using ITensorQuantumOperatorDefinitions:
OpName, SiteType, StateName, ValName, op, siteind, siteinds, state, val
using Test: @test
````

Examples go here.
States and operators as Julia arrays

````julia
@test val(ValName("Up"), SiteType("S=1/2")) == 1
@test val(ValName("Dn"), SiteType("S=1/2")) == 2
@test state(StateName("Up"), SiteType("S=1/2")) == [1, 0]
@test state(StateName("Dn"), SiteType("S=1/2")) == [0, 1]
@test op(OpName("X"), SiteType("S=1/2")) == [0 1; 1 0]
@test op(OpName("Z"), SiteType("S=1/2")) == [1 0; 0 -1]
````

Index constructors

````julia
@test siteind("S=1/2") isa Index
@test Int(length(siteind("S=1/2"))) == 2
@test "S=1/2" in tags(siteind("S=1/2"))
@test siteinds("S=1/2", 4) isa Vector{<:Index}
@test length(siteinds("S=1/2", 4)) == 4
@test all(s -> "S=1/2" in tags(s), siteinds("S=1/2", 4))
````

States and operators as ITensors

````julia
s = Index(2, "S=1/2")
@test val(s, "Up") == 1
@test val(s, "Dn") == 2
@test state("Up", s) == ITensor([1, 0], (s,))
@test state("Dn", s) == ITensor([0, 1], (s,))
@test op("X", s) == ITensor([0 1; 1 0], (s', s))
@test op("Z", s) == ITensor([1 0; 0 -1], (s', s))
````

---

Expand Down
9 changes: 7 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ using ITensorQuantumOperatorDefinitions: ITensorQuantumOperatorDefinitions
using Documenter: Documenter, DocMeta, deploydocs, makedocs

DocMeta.setdocmeta!(
ITensorQuantumOperatorDefinitions, :DocTestSetup, :(using ITensorQuantumOperatorDefinitions); recursive=true
ITensorQuantumOperatorDefinitions,
:DocTestSetup,
:(using ITensorQuantumOperatorDefinitions);
recursive=true,
)

include("make_index.jl")
Expand All @@ -20,5 +23,7 @@ makedocs(;
)

deploydocs(;
repo="github.com/ITensor/ITensorQuantumOperatorDefinitions.jl", devbranch="main", push_preview=true
repo="github.com/ITensor/ITensorQuantumOperatorDefinitions.jl",
devbranch="main",
push_preview=true,
)
1 change: 1 addition & 0 deletions examples/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[deps]
ITensorBase = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
ITensorQuantumOperatorDefinitions = "fd9b415b-e710-4e2a-b407-cba023081494"
31 changes: 29 additions & 2 deletions examples/README.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,32 @@ julia> Pkg.add("ITensorQuantumOperatorDefinitions")

# ## Examples

using ITensorQuantumOperatorDefinitions: ITensorQuantumOperatorDefinitions
# Examples go here.
using ITensorBase: ITensor, Index, tags
using ITensorQuantumOperatorDefinitions:
OpName, SiteType, StateName, ValName, op, siteind, siteinds, state, val
using Test: @test

# States and operators as Julia arrays
@test val(ValName("Up"), SiteType("S=1/2")) == 1
@test val(ValName("Dn"), SiteType("S=1/2")) == 2
@test state(StateName("Up"), SiteType("S=1/2")) == [1, 0]
@test state(StateName("Dn"), SiteType("S=1/2")) == [0, 1]
@test op(OpName("X"), SiteType("S=1/2")) == [0 1; 1 0]
@test op(OpName("Z"), SiteType("S=1/2")) == [1 0; 0 -1]

# Index constructors
@test siteind("S=1/2") isa Index
@test Int(length(siteind("S=1/2"))) == 2
@test "S=1/2" in tags(siteind("S=1/2"))
@test siteinds("S=1/2", 4) isa Vector{<:Index}
@test length(siteinds("S=1/2", 4)) == 4
@test all(s -> "S=1/2" in tags(s), siteinds("S=1/2", 4))

# States and operators as ITensors
s = Index(2, "S=1/2")
@test val(s, "Up") == 1
@test val(s, "Dn") == 2
@test state("Up", s) == ITensor([1, 0], (s,))
@test state("Dn", s) == ITensor([0, 1], (s,))
@test op("X", s) == ITensor([0 1; 1 0], (s', s))
@test op("Z", s) == ITensor([1 0; 0 -1], (s', s))
13 changes: 12 additions & 1 deletion src/ITensorQuantumOperatorDefinitions.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
module ITensorQuantumOperatorDefinitions

# Write your package code here.
include("sitetype.jl")
include("ITensorQuantumOperatorDefinitionsChainRulesCoreExt.jl")
include("sitetypes/aliases.jl")
include("sitetypes/generic_sites.jl")
include("sitetypes/qubit.jl")
include("sitetypes/spinhalf.jl")
include("sitetypes/spinone.jl")
include("sitetypes/fermion.jl")
include("sitetypes/electron.jl")
include("sitetypes/tj.jl")
include("sitetypes/qudit.jl")
include("sitetypes/boson.jl")

end
10 changes: 10 additions & 0 deletions src/ITensorQuantumOperatorDefinitionsChainRulesCoreExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module ITensorQuantumOperatorDefinitionsChainRulesCoreExt

using ChainRulesCore: @non_differentiable
using ..ITensorQuantumOperatorDefinitions: SiteType, _sitetypes, has_fermion_string

@non_differentiable has_fermion_string(::AbstractString, ::Any)
@non_differentiable SiteType(::Any)
@non_differentiable _sitetypes(::Any)

end
Loading

0 comments on commit f11870e

Please sign in to comment.