This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module HoistMem | |
| export hoist_alloc, Buffer | |
| using Cassette, LinearAlgebra | |
| using Cassette: @context, overdub | |
| @context BuffCtx | |
| mutable struct Buffer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using TNFilters | |
| using Flux | |
| using Zygote | |
| using BenchmarkTools | |
| using TNFilters: bmm, bmm!, batched_tr | |
| using Flux: params | |
| using Zygote: AContext, Context, _pullback, cache, accum_param | |
| # I have not found why yet, the manual generated result roughly gives the same performance as Tracker (Tracker is about 35μs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using LinearAlgebra | |
| using LinearAlgebra: promote_op, matprod | |
| # multiply 2x2 matrices | |
| function matmul2x2(tA, tB, A::AbstractArray{T, 3}, B::AbstractArray{S, 3}) where {T,S} | |
| matmul2x2!(similar(B, promote_op(matprod, T, S), 2, 2, size(A, 3)), tA, tB, A, B) | |
| end | |
| function matmul2x2!(C::AbstractArray{T1, 3}, tA, tB, A::AbstractArray{T2, 3}, B::AbstractArray{T3, 3}) where {T1,T2,T3} | |
| if !(size(A) == size(B) == size(C) == (2,2, size(A, 3))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Zygote: @adjoint, _pullback, Context, cache | |
| using AutoPreallocation | |
| using Cassette | |
| export expect, ∇expect, exact_expect, ∇exact_expect | |
| using AutoPreallocation: RecordingCtx, ReplayCtx | |
| # https://github.com/oxinabox/AutoPreallocation.jl/pull/9 | |
| @inline Cassette.overdub(ctx::RecordingCtx, ::typeof(Base.haskey), collection, key) = haskey(collection, key) | |
| @inline Cassette.overdub(ctx::ReplayCtx, ::typeof(Base.haskey), collection, key) = haskey(collection, key) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Flux | |
| struct Linear{T, WT <: AbstractMatrix{T}, BT <: AbstractVector{T}} | |
| W::WT | |
| b::BT | |
| end | |
| Flux.functor(m::Linear) = (m.W, m.b), (W, b) -> Linear(W, b) | |
| m = Linear(rand(2, 2), rand(2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using CUDA | |
| using ExponentialUtilities | |
| using LinearAlgebra | |
| using BenchmarkTools | |
| using ExponentialUtilities: getV, getH, get_cache, _exp! | |
| using LinearAlgebra: BlasReal, BlasComplex | |
| using SparseArrays | |
| using CUDA: CUBLAS | |
| CUDA.allowscalar(false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Dates | |
| function count_hours(m) | |
| days = filter(Date(2020, m, 14): Day(1):Date(2020, m+1, 13)) do day | |
| !(dayname(day) in ["Saturday", "Sunday"]) | |
| end | |
| return length(days) * 8 | |
| end | |
| count_hours(7) * 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using YaoCompiler | |
| using YaoCompiler.Intrinsics | |
| qasm"""OPENQASM 2.0; | |
| include "qelib1.inc"; | |
| gate post q {x q;} | |
| """ | |
| @device function circuit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| macro _threads(ex) | |
| return quote | |
| if (Threads.nthreads() > 1) && (length(st) > 4096) | |
| $(Expr(:macrocall, Expr(:(.), :Threads, QuoteNode(Symbol("@threads"))), __source__, ex)) | |
| else | |
| $ex | |
| end | |
| end |> esc | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Random | |
| using Yao | |
| using Plots | |
| using LinearAlgebra | |
| using QuantumInformation | |
| function run_circuit!(r::AbstractRegister, θs::Matrix, p::Real=0.0) | |
| n = nqubits(r) | |
| for j in 1:size(θs, 2) # each layer | |
| for i in 1:size(θs, 1)÷2 # each wire |