Julia Cheat Sheet

Updating...

system

@__File__
@__DIR__
Base.active_project()

Plot

draw histogram

h = fit(Histogram, s, nbins=500)
# @show h
# normalize(h,mode=:pdf)
r = h.edges[1]
w = 0.0
for i in h.weights
    global w += i*step(r)
end
x = first(r)+step(r)/2:step(r):last(r)
plot(x, h.weights/w,norm=true)

Test

UnitTest Julia
@testset "Name" begin
    @test 1==1
end

Style

Variables

MODULENAME: HOWSM

StructName: System

function_name: qc_struct_2d;
bbh_h_3d;

multi-dimension-variables
iL = 1:length(Ls)
L = Ls[iL]

Documents


"""
(a four-space indent) signature of the function 

one-line explanation

more details in a second paragraph with a blank line

# Arguments(if necessary)
- `n::Integer`: the number of elements to compute.
- `dim::Integer=1`: the dimensions along which to perform the computation.

See also [`bar!`](@ref), [`baz`](@ref), [`baaz`](@ref)

#Examples
```jldoctest
julia> a = [1 2; 3 4]
2×2 Array{Int64,2}:
 1  2
 3  4
```

"""

Syntactic sugar

Short-Circuit Evaluation
a && b execute b if a is true
a || b execute b if a is false

meta coding

for fname in (
  :dag,
  :prime,
  :setprime,
  :noprime,
  :swapprime,
  :replaceprime,
  :addtags,
  :removetags,
  :replacetags,
  :settags,
)
  fname! = Symbol(fname, :!)

  @eval begin
    """
        $($fname)[!](M::MPS, args...; kwargs...)
        $($fname)[!](M::MPO, args...; kwargs...)

    Apply $($fname) to all ITensors of an MPS/MPO, returning a new MPS/MPO.

    The ITensors of the MPS/MPO will be a view of the storage of the original ITensors. Alternatively apply the function in-place.
    """
    function $fname(M::AbstractMPS, args...; set_limits::Bool=false, kwargs...)
      return map(m -> $fname(m, args...; kwargs...), M; set_limits=set_limits)
    end

    function $(fname!)(M::AbstractMPS, args...; set_limits::Bool=false, kwargs...)
      return map!(m -> $fname(m, args...; kwargs...), M; set_limits=set_limits)
    end
  end
end

标签: none

评论已关闭