def main():

    results_root = pjoin(mm.rootdir(), "experiments", "parameter_sweeps", "odblock-eigs")

    for _rdir in os.listdir(results_root):
        results_dir = pjoin(results_root, _rdir)

        data = mm.parse_run(results_dir)

        if data is None:
            continue

        print("\nrefinement level", data['refinement'])
        print("disable-ms?", data['disable-ms'])

        first_m_block = 2
        nblock = 5

        # Just first Jacobian for now
        with warnings.catch_warnings():
            A = omat.import_blocks(pjoin(results_dir, "J_3_1_block"), nblock)

        # Get only LLG blocks
        A = omat.sub_matrix(A, first_m_block)

        # Get only offdiagonal blocks
        A = omat.off_diagonal_blocks(A)

        evs = []
        non_sym = []
        for block in A.flat:
            if block.nnz > 0:
                ev, evec = sp.sparse.linalg.eigs(block)
                evs.append(ev)
                TT = block - block.T

                nnz = len(filter(lambda x: x> 1e-8, TT.data))
                non_sym.append(nnz)

                # if nnz > 0:
                #     print(sp.mean(block.data))
                #     print(TT)


        # print("overall abs", map(maxabs, evs))
        # print("max real part", map(maxreal, evs))
        print("max imaginary part", max(map(maximag, evs)))

        print("max nnz in B - B^T", max(non_sym))



    return 0
def try_run(args, dt, dir_naming_args, root_outdir,
             maxallowederror = 0.01, maxallowedangle = sp.pi/4):

    args.update({'-dt' : dt})

    # Try to run it
    err_code, outdir = mm._run(args, root_outdir, dir_naming_args,
                                quiet=True)


    # Parse output files
    data = mm.parse_run(outdir)
    if data is not None:
        errs = data['m_length_error_means']
        assert errs[0] >= 0
        maxerror = max(errs)

        angles = data['max_angle_errors']
        maxangle = max(angles)

        maxtime = data['times'][-1]
        nsteps = len(data['times'])

    else:
        maxerror = sp.inf
        maxangle = sp.inf
        maxtime = 0
        nsteps = 0

    success = (err_code == 0 and maxerror < maxallowederror
                and maxangle < maxallowedangle)

    if success:
        mm.okprint("Succedded in", data['-outdir'])
    else:
        mm.badprint(pjoin(data['-outdir'], "stdout:1:1:"), "FAILED")

    return success, data