Skip to content

Commit f11870e

Browse files
authored
First commit (move code from ITensors.jl) (#1)
1 parent 7da3e9f commit f11870e

20 files changed

+2576
-8
lines changed

Project.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@ uuid = "fd9b415b-e710-4e2a-b407-cba023081494"
33
authors = ["ITensor developers <[email protected]> and contributors"]
44
version = "0.1.0"
55

6+
[deps]
7+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
8+
ITensorBase = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
9+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
10+
611
[compat]
12+
ChainRulesCore = "1.25.1"
13+
ITensorBase = "0.1.8"
14+
LinearAlgebra = "1.10"
715
julia = "1.10"

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,45 @@ julia> Pkg.add("ITensorQuantumOperatorDefinitions")
3232
## Examples
3333

3434
````julia
35-
using ITensorQuantumOperatorDefinitions: ITensorQuantumOperatorDefinitions
35+
using ITensorBase: ITensor, Index, tags
36+
using ITensorQuantumOperatorDefinitions:
37+
OpName, SiteType, StateName, ValName, op, siteind, siteinds, state, val
38+
using Test: @test
3639
````
3740

38-
Examples go here.
41+
States and operators as Julia arrays
42+
43+
````julia
44+
@test val(ValName("Up"), SiteType("S=1/2")) == 1
45+
@test val(ValName("Dn"), SiteType("S=1/2")) == 2
46+
@test state(StateName("Up"), SiteType("S=1/2")) == [1, 0]
47+
@test state(StateName("Dn"), SiteType("S=1/2")) == [0, 1]
48+
@test op(OpName("X"), SiteType("S=1/2")) == [0 1; 1 0]
49+
@test op(OpName("Z"), SiteType("S=1/2")) == [1 0; 0 -1]
50+
````
51+
52+
Index constructors
53+
54+
````julia
55+
@test siteind("S=1/2") isa Index
56+
@test Int(length(siteind("S=1/2"))) == 2
57+
@test "S=1/2" in tags(siteind("S=1/2"))
58+
@test siteinds("S=1/2", 4) isa Vector{<:Index}
59+
@test length(siteinds("S=1/2", 4)) == 4
60+
@test all(s -> "S=1/2" in tags(s), siteinds("S=1/2", 4))
61+
````
62+
63+
States and operators as ITensors
64+
65+
````julia
66+
s = Index(2, "S=1/2")
67+
@test val(s, "Up") == 1
68+
@test val(s, "Dn") == 2
69+
@test state("Up", s) == ITensor([1, 0], (s,))
70+
@test state("Dn", s) == ITensor([0, 1], (s,))
71+
@test op("X", s) == ITensor([0 1; 1 0], (s', s))
72+
@test op("Z", s) == ITensor([1 0; 0 -1], (s', s))
73+
````
3974

4075
---
4176

docs/make.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ using ITensorQuantumOperatorDefinitions: ITensorQuantumOperatorDefinitions
22
using Documenter: Documenter, DocMeta, deploydocs, makedocs
33

44
DocMeta.setdocmeta!(
5-
ITensorQuantumOperatorDefinitions, :DocTestSetup, :(using ITensorQuantumOperatorDefinitions); recursive=true
5+
ITensorQuantumOperatorDefinitions,
6+
:DocTestSetup,
7+
:(using ITensorQuantumOperatorDefinitions);
8+
recursive=true,
69
)
710

811
include("make_index.jl")
@@ -20,5 +23,7 @@ makedocs(;
2023
)
2124

2225
deploydocs(;
23-
repo="github.com/ITensor/ITensorQuantumOperatorDefinitions.jl", devbranch="main", push_preview=true
26+
repo="github.com/ITensor/ITensorQuantumOperatorDefinitions.jl",
27+
devbranch="main",
28+
push_preview=true,
2429
)

examples/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[deps]
2+
ITensorBase = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
23
ITensorQuantumOperatorDefinitions = "fd9b415b-e710-4e2a-b407-cba023081494"

examples/README.jl

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,32 @@ julia> Pkg.add("ITensorQuantumOperatorDefinitions")
3737

3838
# ## Examples
3939

40-
using ITensorQuantumOperatorDefinitions: ITensorQuantumOperatorDefinitions
41-
# Examples go here.
40+
using ITensorBase: ITensor, Index, tags
41+
using ITensorQuantumOperatorDefinitions:
42+
OpName, SiteType, StateName, ValName, op, siteind, siteinds, state, val
43+
using Test: @test
44+
45+
# States and operators as Julia arrays
46+
@test val(ValName("Up"), SiteType("S=1/2")) == 1
47+
@test val(ValName("Dn"), SiteType("S=1/2")) == 2
48+
@test state(StateName("Up"), SiteType("S=1/2")) == [1, 0]
49+
@test state(StateName("Dn"), SiteType("S=1/2")) == [0, 1]
50+
@test op(OpName("X"), SiteType("S=1/2")) == [0 1; 1 0]
51+
@test op(OpName("Z"), SiteType("S=1/2")) == [1 0; 0 -1]
52+
53+
# Index constructors
54+
@test siteind("S=1/2") isa Index
55+
@test Int(length(siteind("S=1/2"))) == 2
56+
@test "S=1/2" in tags(siteind("S=1/2"))
57+
@test siteinds("S=1/2", 4) isa Vector{<:Index}
58+
@test length(siteinds("S=1/2", 4)) == 4
59+
@test all(s -> "S=1/2" in tags(s), siteinds("S=1/2", 4))
60+
61+
# States and operators as ITensors
62+
s = Index(2, "S=1/2")
63+
@test val(s, "Up") == 1
64+
@test val(s, "Dn") == 2
65+
@test state("Up", s) == ITensor([1, 0], (s,))
66+
@test state("Dn", s) == ITensor([0, 1], (s,))
67+
@test op("X", s) == ITensor([0 1; 1 0], (s', s))
68+
@test op("Z", s) == ITensor([1 0; 0 -1], (s', s))
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
module ITensorQuantumOperatorDefinitions
22

3-
# Write your package code here.
3+
include("sitetype.jl")
4+
include("ITensorQuantumOperatorDefinitionsChainRulesCoreExt.jl")
5+
include("sitetypes/aliases.jl")
6+
include("sitetypes/generic_sites.jl")
7+
include("sitetypes/qubit.jl")
8+
include("sitetypes/spinhalf.jl")
9+
include("sitetypes/spinone.jl")
10+
include("sitetypes/fermion.jl")
11+
include("sitetypes/electron.jl")
12+
include("sitetypes/tj.jl")
13+
include("sitetypes/qudit.jl")
14+
include("sitetypes/boson.jl")
415

516
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module ITensorQuantumOperatorDefinitionsChainRulesCoreExt
2+
3+
using ChainRulesCore: @non_differentiable
4+
using ..ITensorQuantumOperatorDefinitions: SiteType, _sitetypes, has_fermion_string
5+
6+
@non_differentiable has_fermion_string(::AbstractString, ::Any)
7+
@non_differentiable SiteType(::Any)
8+
@non_differentiable _sitetypes(::Any)
9+
10+
end

0 commit comments

Comments
 (0)