Skip to content

Instantly share code, notes, and snippets.

@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
@sergei-mironov
sergei-mironov / ca-bundle-rf.crt
Last active September 13, 2021 12:19
ca-bundle-rf.crt
0?0?��NmG?&?}ev?\?ӓ0
*?0?$10 *?H??
 [email protected] 0 URU10U 77 Москва10U г. Москва1.0,U %улица Тверская, дом 71,0*U
#Минкомсвязь России10*?d
104770202670110*?? 0077104743751,0*U #Минкомсвязь России0
180706121806Z
360701121806Z0?$10 *?H??
 [email protected] 0 URU10U 77 Москва10U г. Москва1.0,U %улица Тверская, дом 71,0*U
#Минкомсвязь России10*?d
104770202670110*?? 0077104743751,0*U #Минкомсвязь России0f0*?0*?#*?C@u9*E????}??"???Zq?}}X??F?EaW??H??J?H?j)????xq?G?????6???????0??0??*?dp??0?? 4ПАКМ «КриптоПро HSM» версии 2.0 CПАК «Головной удостоверяющий центр» 5Заключение № 149/3/2/2/23 от 02.03.2018 4Заключение № 149/7/6/105 от 27.06.20180?*?do6 4ПАКМ «КриптоПро HSM» версии 2.00CU <0:0*?dq0*?dq0*?dq0*?dq0*?dq0U 0U?0U?0?0U?T??k?L??m6?#????<?0
@sergei-mironov
sergei-mironov / latex2pdf.py
Created September 3, 2021 14:48
latex2pdf
def latex2pdf(expr:str,
out_pdf:Filepath,
font:str='normalsize',
font_white:bool=False,
texname:str='latex'
)->None:
makedirs('_tex',exist_ok=True)
tex=f'_tex/{texname}.tex'
pdf=f'_tex/{texname}.pdf'
with open(tex, 'w') as f: