Skip to content

Instantly share code, notes, and snippets.

View garrison's full-sized avatar
🚧

Jim Garrison garrison

🚧
View GitHub Profile
@garrison
garrison / tnqs-pr109-import-probes.md
Created October 28, 2026 21:04
Probes against TensorNetworkQuantumSimulator.jl PR #109 β€” Qiskit/QASM import

Probes against TensorNetworkQuantumSimulator.jl PR #109 β€” Qiskit/QASM import

Notes from reading and exercising the circuit-import path at 95ff373. Posted as an appendix to a review comment on the PR. Everything below was run, not inferred.

Gate coverage. All 37 one- and two-qubit gates in Qiskit.jl's GATE_TABLE import via circuit_from_qasm and apply successfully through apply_gates on a 2-site graph. Swept id x y z h s sdg sx sxdg t tdg p rx ry rz r u and cx cy cz ch dcx ecr swap iswap cs csdg csx cp crx cry crz rxx ryy rzz rzx cu. No failures.

Both import routes agree. The same circuit through circuit_from_qasm and circuit_from_qiskit yields identical gate tuples and identical expectation values:

qasm gates   = [("H", [1]), ("H", [2]), ("Rzz", [1, 2], 0.7)]
@garrison
garrison / counter-based-prng-notes.md
Created October 28, 2026 19:04
Notes on counter-based PRNG substream addressing and seed folding, re: Qiskit/qiskit#17346

Qiskit/qiskit#17346 proposes counter-based PRNG operations for quantum programs, and raises the question of how the choice of protocol should be represented. I've been using a counter-based generator in qiskit-addon-sqd-hpc for the same reasons, and arrived at the typed-key conclusion of JEP 9263 from the other direction. These are a few notes from that experience, in case any of it is useful.

Substream addressing needs stride, not adjacency. The proposal makes the counter the row-major flat index into the payload shape. That is safe as long as each output element consumes exactly one block, but it stops being safe once distributions are built on top. A rejection sampler's draw count per item is unbounded, and the draws consumed per sample by a given distribution are typically unspecified, so with adjacent counters item i's draws n..2n-1 are i

@garrison
garrison / Manifest.toml
Created June 20, 2026 01:15
Current Manifest.toml for Qiskit.jl generation
# This file is machine-generated - editing it directly is not advised
julia_version = "1.12.6"
manifest_format = "2.0"
project_hash = "3faf089ceb1073c65bf44a4a2103b84592e931ab"
[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.2"
@garrison
garrison / gist:d974aaeda947a0674c3012391fcb9970
Created January 1, 2022 03:15
Julia e8d116735cfa under Valgrind
$ valgrind --smc-check=all-non-file --suppressions=contrib/valgrind-julia.supp --leak-check=full --show-leak-kinds=definite ./julia -e ""
==xxxxxx== Memcheck, a memory error detector
==xxxxxx== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==xxxxxx== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==xxxxxx== Command: ./julia -e
==xxxxxx==
==xxxxxx==
==xxxxxx== HEAP SUMMARY:
==xxxxxx== in use at exit: 97,755,918 bytes in 75,184 blocks
==xxxxxx== total heap usage: 166,179 allocs, 90,995 frees, 104,815,918 bytes allocated
@garrison
garrison / build-log
Last active September 19, 2021 02:09
ekam build failure with ccache on Fedora 34
This file has been truncated, but you can view the full file.
[vagrant@fedora34 ~]$ git clone https://github.com/capnproto/ekam.git
Cloning into 'ekam'...
remote: Enumerating objects: 2218, done.
remote: Counting objects: 100% (273/273), done.
remote: Compressing objects: 100% (159/159), done.
remote: Total 2218 (delta 189), reused 167 (delta 113), pack-reused 1945
Receiving objects: 100% (2218/2218), 1.89 MiB | 2.32 MiB/s, done.
Resolving deltas: 100% (1599/1599), done.
[vagrant@fedora34 ~]$ cd ekam
[vagrant@fedora34 ekam]$ nano Makefile
@garrison
garrison / Dockerfile.debian
Last active August 5, 2022 00:35
Sandstorm Docker builds
# buster compiles just fine.
# bullseye works, with some warnings about "not a dynamic executable" at the end. My own testing has shown that the resulting package works, as expected since Kenton claims on IRC to use bullseye.
FROM debian:bullseye
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y build-essential libcap-dev xz-utils zip \
unzip strace curl discount git python3 zlib1g-dev \
golang-go cmake strace flex bison locales
# Install meteor as a regular user; otherwise the build cannot find node.h.
(v1.0) pkg> add RandomMatrices
Updating registry at `~/.julia/registries/General`
Updating git-repo `https://github.com/JuliaRegistries/General.git`
Resolving package versions...
Installed CMake ─────────────────────── v1.0.2
Installed GenericSVD ────────────────── v0.2.0
Installed DataStructures ────────────── v0.12.0
Installed NLSolversBase ─────────────── v7.1.0
Installed RandomMatrices ────────────── v0.4.0
Installed DiffEqBase ────────────────── v4.25.0
@garrison
garrison / indexin.txt
Created January 20, 2018 15:00
Uses of `indexin` in julia package ecosystem
./BayesNets/src/Factors/factors_dims.jl: index_common1 = indexin(common, Ο•1.dimensions)
./BayesNets/src/Factors/factors_dims.jl: index_common2 = indexin(common, Ο•2.dimensions)
./BayesNets/src/Factors/factors_dims.jl: index_unique1 = indexin(unique1, Ο•1.dimensions)
./BayesNets/src/Factors/factors_dims.jl: index_unique2 = indexin(unique2, Ο•2.dimensions)
./BayesNets/src/Factors/factors_dims.jl: inds = (indexin(dims, Ο•)...)
./BayesNets/src/Factors/factors_dims.jl: inds = (indexin(dims, Ο•)...)
./BayesNets/src/Factors/factors_dims.jl: inds = indexin(dims, Ο•)
./BayesNets/src/Factors/factors_dims.jl: inds = indexin(dims, Ο•)
./BayesNets/src/Factors/factors_main.jl:Base.indexin(dim::NodeName, Ο•::Factor) = findnext(Ο•.dimensions, dim, 1)
./BayesNets/src/Factors/factors_main.jl:Base.indexin(dims::NodeNames, Ο•::Factor) = indexin(dims, names(Ο•))
ArrayFire/generate/generate.jl: "is_sparse" => "issparse", "sparse_to_dense" => "full",
ArrayFire/src/array.jl:import Base: Array, SparseMatrixCSC, copy, deepcopy_internal, issparse, sparse, full, complex, conj
ArrayFire/src/util.jl: @assert issparse(a) "AFArray is not sparse"
ArrayFire/src/util.jl: if issparse(a)
ArrayFire/src/util.jl:toa(a) = issparse(a) ? SparseMatrixCSC(a) : Array(a)
ArrayFire/src/wrap.jl:export is_row, is_scalar, is_single, is_vector, is_window_closed, isinf, isnan, issparse, iszero, le, lgamma
ArrayFire/src/wrap.jl:function issparse(arr::AFArray)
ArrayFire/test/sparse.jl:@test !issparse(A)
ArrayFire/test/sparse.jl:@test issparse(a1)
ArrayFire/test/sparse.jl:@test issparse(Aid)
$ valgrind -q --smc-check=all --suppressions=/home/garrison/julia/contrib/valgrind-julia.supp --trace-children=yes make
CC src/jltypes.o
CC src/gf.o
FLISP src/julia_flisp.boot
FLISP src/julia_flisp.boot.inc
CC src/ast.o
CC src/builtins.o
CC src/module.o
CC src/codegen.o
In file included from codegen.cpp:746:0: