"""Probe the qector-decoder-v3 v0.6.7 Rust core directly (bypassing broken __init__)."""
import json
import numpy as np
from qload import load_core

native, pyd = load_core()
print("=== LOADED:", pyd)
syms = sorted(x for x in dir(native) if not x.startswith("__"))
print("=== NATIVE SYMBOLS ===")
print(json.dumps(syms))
print("HybridCascadeDecoder present:", hasattr(native, "HybridCascadeDecoder"))
print("HybridDecoder present:", hasattr(native, "HybridDecoder"))

print("=== GPU AVAILABILITY ===")
for fn in ("cuda_is_available", "opencl_is_available"):
    try:
        print(fn, "->", getattr(native, fn)())
    except Exception as e:
        print(fn, "ERR", repr(e))
for cls in ("CUDABatchDecoder", "OpenCLBatchDecoder"):
    try:
        print(cls + ".is_available ->", getattr(native, cls).is_available())
    except Exception as e:
        print(cls, "ERR", repr(e))

print("=== SURFACE CODE SHAPES ===")
gen = native.py_generate_surface_code_checks
for d in (3, 5, 7, 9, 19):
    checks = gen(d)
    checks = [list(c) for c in checks]
    nq = 1 + max(q for c in checks for q in c)
    print(f"d={d}: n_checks={len(checks)} n_qubits(max+1)={nq} first={checks[0]} last={checks[-1]}")

print("=== SMOKE DECODE (d3) ===")
checks = [list(c) for c in gen(3)]
nq = 1 + max(q for c in checks for q in c)
uf = native.UnionFindDecoder(checks, nq)
bl = native.BlossomDecoder(checks, nq)
syn = np.zeros(len(checks), dtype=np.uint8)
syn[0] = 1
print("UF n_qubits/n_checks:", uf.n_qubits, uf.n_checks)
print("UF decode:", uf.decode(syn).tolist())
print("Blossom decode:", bl.decode(syn).tolist())
syns = np.zeros((5, len(checks)), dtype=np.uint8)
syns[:, 0] = 1
out = uf.batch_decode(syns)
print("UF batch shape:", out.shape, "dtype:", out.dtype)
print("PROBE OK")
