Skip to content

Instantly share code, notes, and snippets.

@sergei-mironov
sergei-mironov / logical_cnot_null.py
Created March 20, 2026 06:45
logical_cnot_null.py
""" PennyLane/Catalyst kernel translated from a Stim circuit.
193 qubits, 1345 measurements.
"""
import catalyst
import pennylane as qml
from pennylane import qjit
print("TRACING", flush=True)
@qjit
import catalyst
import pennylane as qml
from time import time
from json import dump as json_dump
@qml.qjit
@qml.qnode(
qml.device(
"qrack.simulator",
@sergei-mironov
sergei-mironov / jax-dynamic-api.md
Created November 10, 2023 10:24
Studying JAX v0.4.19 dynamic API

Studying JAX v0.4.19 dynamic API

Indexing with constants (runs, bad results)

Note: related JAX test

func, mlir, jaxpr = None, None, None
@sergei-mironov
sergei-mironov / jax-0.4.19-dynshape.patch
Created November 10, 2023 10:14
jax-0.4.19-dynshape.patch
diff --git a/jax/_src/interpreters/mlir.py b/jax/_src/interpreters/mlir.py
index d168d22ab..798d07a6d 100644
--- a/jax/_src/interpreters/mlir.py
+++ b/jax/_src/interpreters/mlir.py
@@ -1461,7 +1461,7 @@ def jaxpr_subcomp(ctx: ModuleContext, jaxpr: core.Jaxpr,
ans, "lowering function returned a bad output", eqn)
assert len(ans) == len(eqn.outvars), (ans, eqn)
map(write, eqn.outvars, out_nodes)
- core.clean_up_dead_vars(eqn, env, last_used)
+ # core.clean_up_dead_vars(eqn, env, last_used)
@sergei-mironov
sergei-mironov / output.md
Created October 18, 2023 20:17
output.md
@qjit(autograph=True, verbose=True, keep_intermediate=True)
@qml.qnode(qml.device("lightning.qubit", wires=1))
def fn(x: float):
    qml.RY(x, wires=0)
    return qml.expval(qml.PauliZ(0))

fn(np.pi)
@sergei-mironov
sergei-mironov / error.txt
Created October 10, 2023 13:20
Classical pre-processing not working when using grad with enzyme
Traceback (most recent call last):
File "/workspace/modules/catalyst/frontend/catalyst/compiler.py", line 365, in run_from_ir
compiler_output = run_compiler_driver(
RuntimeError: Compilation failed:
f:6:3: error: operand #0 does not dominate this use
func.func private @"<lambda>"(%arg0: tensor<f64>) -> tensor<f64> attributes {llvm.linkage = #llvm.linkage<internal>} {
^
f:6:3: note: diagnostic emitted with trace:
#0 0x00007f08dcb4ac13 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/workspace/_build_dialects/python_packages/quantum/mlir_quantum/compiler_driver.so+0x8b4ac13)
#1 0x00007f08da98c1b9 emitDiag(mlir::Location, mlir::DiagnosticSeverity, llvm::Twine const&) Diagnostics.cpp:0:0
module @C_workflow {
llvm.func @__quantum__rt__finalize()
llvm.func @__quantum__rt__initialize()
llvm.mlir.global internal constant @backend_best("best\00") {addr_space = 0 : i32}
llvm.mlir.global internal constant @backend("backend\00") {addr_space = 0 : i32}
llvm.func @__quantum__rt__device(!llvm.ptr<i8>, !llvm.ptr<i8>)
llvm.func @free(!llvm.ptr<i8>)
llvm.func @malloc(i64) -> !llvm.ptr<i8>
llvm.mlir.global private constant @__constant_4x3x4xf64(dense<9.9999999999999995E-8> : tensor<4x3x4xf64>) {addr_space = 0 : i32} : !llvm.array<4 x array<3 x array<4 x f64>>>
llvm.mlir.global private constant @__constant_4x4xf64(dense<9.9999999999999995E-8> : tensor<4x4xf64>) {addr_space = 0 : i32} : !llvm.array<4 x array<4 x f64>>
@sergei-mironov
sergei-mironov / scatter_reference.py
Created April 11, 2023 13:16
Reference implementation if MHLO::Scatter in Python
from frozendict import frozendict
from typing import List, Any, Callable
from copy import deepcopy
Dim = int # Dimention "names"
Index = Dict[Dim, int] # `Index :: Dimention -> Coordinate`
# (To-be implemented as Frozendict to make Python data hashable)
Value = complex # A value
Tensor = Dict[Index, Value] # `Tensor :: Index -> Value`
@sergei-mironov
sergei-mironov / test.md
Last active February 10, 2023 18:45
test_markdown

V1

print("with attrs")
with attrs
enable prepare protect duty hardware
clock count count count rate accuracy phase cycle enable
-------------------------------------------------------------------------------------------------------
iosc 1 1 0 16000000 300000000 0 50000 Y
ar100 1 1 0 16000000 300000000 0 50000 Y
ahb0 1 1 0 16000000 300000000 0 50000 Y
apb0 2 2 0 16000000 300000000 0 50000 Y
apb0-twd 1 1 0 16000000 300000000 0 50000 Y
apb0-i2c 0 0 0 16000000 300000000 0 50000 N
apb0-uart 0 0 0 16000000 300000000 0