def almost_unitary(gate: Gate) -> bool:
    """Return true if gate tensor is (almost) unitary"""
    res = (gate @ gate.H).asoperator()
    N = gate.qubit_nb
    return np.allclose(asarray(res), np.eye(2**N), atol=TOLERANCE)
Return true if gate tensor is (almost) unitary