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 MacroTools | |
using MacroTools: striplines | |
### | |
### Macros | |
### | |
""" | |
@qc code |
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
import numpy as np | |
ZCHOP_EPS = 1e-12 | |
def zchop_real_np(m, eps=ZCHOP_EPS): | |
m[abs(m) < eps] = 0.0 | |
return m | |
def zchop(m, eps=ZCHOP_EPS): | |
if isinstance(m, float): |
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
from qiskit.quantum_info import SparsePauliOp, Operator | |
from qiskit.opflow import PauliSumOp, AbelianGrouper | |
import numpy as np | |
def try_sparse_pauli_op(n=1): | |
mat = np.random.rand(2**n, 2**n) | |
omat = Operator(mat) | |
sp = SparsePauliOp.from_operator(omat) | |
return sp | |
def get_pauli_sum_op(n=1): |
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
import numpy | |
## These are the permutation symmetries satisfied by | |
## a rank-4 tensor of real two-body integrals in chemists' | |
## index order. | |
CHEM_INDEX_PERMUTATIONS = [ | |
'pqrs->qprs', # (1.4.38) in HJO book (1) | |
'pqrs->pqsr', # (1.4.38) (2) | |
'pqrs->qpsr', # (1.4.38) (3) | |
'pqrs->rspq', # (1.4.17) (4) |
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
# price schemes | |
struct NormalHours end | |
struct HappyHour end | |
actual_price(price, ::NormalHours) = price | |
actual_price(price, ::HappyHour) = price / 2 | |
struct CustomerBill | |
drinks::Vector{Float64} | |
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
const BLASVENDOR = Compat.LinearAlgebra.BLAS.vendor() | |
@eval Compat.LinearAlgebra.BLAS function get_num_threads end | |
# Following fails in v"0.7.0-DEV.4810". But, this appears to | |
# be a bug. | |
""" | |
BLAS.get_num_threads() | |
Get the number of threads that the BLAS library currently uses. |
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
## This file benchmarks taking slices of lazily-wrapped transpose and adjoint of sparse matrices. | |
## The times appear in triplets. First, the array with no wrapper, then the transpose, then the | |
## adjoint. | |
## The first time should always be the same or a bit faster than the second or third. | |
## (But, @btime was not tuned). | |
## Below is a file with post-PR results and a file with pre-PR results. | |
using BenchmarkTools | |
using SparseArrays | |
using LinearAlgebra |
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
# See the first comment for an explanation | |
using Lazy | |
function walkifs(dim) | |
conditions = Any[] | |
actions = Any[] | |
for i in 1:(2*dim-1) | |
push!(conditions, :( dir == $i )) | |
end | |
for i in 1:dim |
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
doc""" | |
buildif(exprs...) | |
`buildif` builds an if-elseif-else construct programmatically. | |
`buildif` returns an expression equivalent to an if-elseif-else | |
construct, where, if the length of exprs is even, then the odd-indexed | |
elements of exprs are condition expressions and the even-indexed | |
elements are code blocks for the corresponding branches. If the length | |
of exprs is odd, then the last element is the default code block. In |