Beispiel #1
0
def run(arg_parser, entry_function):
    arg_parser.add_argument("--pdb", action='store_true')
    arg_parser.add_argument("--ipdb", action='store_true')
    arg_parser.add_argument("--no_cuda", action='store_true')
    arg_parser.add_argument("--experiment_name", type=str, default='debug')
    arg_parser.add_argument("--batch_size", type=int, default=64)
    arg_parser.add_argument("--save_args", action='store_false')

    args = arg_parser.parse_args()
    print('parameters:')
    print(json.dumps(vars(args), indent=2))

    args = DotDict(vars(args))
    args.RESULT_DIR = os.path.join('tasks/R2R/experiments/',
                                   args.experiment_name, 'results')
    args.SNAPSHOT_DIR = os.path.join('tasks/R2R/experiments/',
                                     args.experiment_name, 'snapshots')
    args.PLOT_DIR = os.path.join('tasks/R2R/experiments/',
                                 args.experiment_name, 'plots')
    make_dirs([args.RESULT_DIR, args.SNAPSHOT_DIR, args.PLOT_DIR])

    import torch.cuda
    torch.cuda.disabled = args.no_cuda

    def log(out_file):
        ''' git updates '''
        subprocess.call("git rev-parse HEAD", shell=True, stdout=out_file)
        subprocess.call("git --no-pager diff", shell=True, stdout=out_file)
        out_file.write('\n\n')
        out_file.write(' '.join(sys.argv))
        out_file.write('\n\n')
        json.dump(dict(args), out_file)
        out_file.write('\n\n')

    #log(sys.stdout)
    if args.save_args:
        import datetime
        now = datetime.datetime.now()
        args_fn = 'args-%d-%d-%d,%d:%d:%d' % (now.year, now.month, now.day,
                                              now.hour, now.minute, now.second)
        with open(os.path.join(args.PLOT_DIR, args_fn), 'w') as f:
            log(f)

    # Make the folders
    args.RESULT_DIR = os.path.join('tasks/R2R/experiments/',
                                   args.experiment_name, 'results')
    args.SNAPSHOT_DIR = os.path.join('tasks/R2R/experiments/',
                                     args.experiment_name, 'snapshots')
    args.PLOT_DIR = os.path.join('tasks/R2R/experiments/',
                                 args.experiment_name, 'plots')
    make_dirs([args.RESULT_DIR, args.SNAPSHOT_DIR, args.PLOT_DIR])

    if args.ipdb:
        import ipdb
        ipdb.runcall(entry_function, args)
    elif args.pdb:
        import pdb
        pdb.runcall(entry_function, args)
    else:
        entry_function(args)
Beispiel #2
0
def run(arg_parser, entry_function):
    arg_parser.add_argument("--pdb", action='store_true')
    arg_parser.add_argument("--ipdb", action='store_true')

    args, other_args = arg_parser.parse_known_args()

    def log(out_file):
        subprocess.call("git rev-parse HEAD", shell=True, stdout=out_file)
        subprocess.call("git --no-pager diff", shell=True, stdout=out_file)
        out_file.write('\n\n')
        out_file.write(' '.join(sys.argv))
        out_file.write('\n\n')
        json.dump(vars(args), out_file)
        out_file.write('\n\n')

    log(sys.stdout)
    # if 'save_dir' in vars(args) and args.save_dir:
    #     with open(os.path.join(args.save_dir, 'invoke.log'), 'w') as f:
    #         log(f)

    if args.ipdb:
        import ipdb
        ipdb.runcall(entry_function, args)
    elif args.pdb:
        import pdb
        pdb.runcall(entry_function, args)
    else:
        entry_function(args)
Beispiel #3
0
def run(arg_parser, entry_function, functions=None):

    args = get_arguments(arg_parser)
    print('parameters:')
    print(json.dumps(vars(args), indent=2))

    args = DotDict(vars(args))

    args.RESULT_DIR = os.path.join('tasks/{}/experiments/'.format(args.prefix),
                                   args.experiment_name, 'results')
    args.SNAPSHOT_DIR = os.path.join(
        'tasks/{}/experiments/'.format(args.prefix), args.experiment_name,
        'snapshots')
    args.PLOT_DIR = os.path.join('tasks/{}/experiments/'.format(args.prefix),
                                 args.experiment_name, 'plots')

    make_dirs([args.RESULT_DIR, args.SNAPSHOT_DIR, args.PLOT_DIR])

    import torch.cuda
    torch.cuda.disabled = args.no_cuda

    if entry_function == None:
        print('will run', args.function)
        entry_function = functions[args.function]
    if args.ipdb:
        import ipdb
        ipdb.runcall(entry_function, args)
    elif args.pdb:
        import pdb
        pdb.runcall(entry_function, args)
    else:
        entry_function(args)
Beispiel #4
0
def debug():
    import ipdb
    import traceback
    try:
        ipdb.runcall(main)
    except Exception as e:
        traceback.print_exc(file=sys.stderr)
        ipdb.post_mortem(e.__traceback__)
Beispiel #5
0
 def check_wrapper(*args, **kwargs):
     nonlocal i
     i = i + 1
     if i == index:
         return runcall(func, *args, **kwargs)
     else:
         return func(*args, **kwargs)
Beispiel #6
0
 def trace_wrapper(*args, **kwargs):
     gen = func(*args, **kwargs)
     try:
         while True:
             yield runcall(next, gen)
     except StopIteration:
         pass
def pdb_runcall(object, args, request):
    """If the request has the pdb_runcall key then we run the result
    of request traversal in the debugger.  Othwise, do it normally.

    A cookie for pdb_runcall may also be set or removed if the request
    has the toggle_runcall key."""
    response = request.response

    if 'toggle_runcall' in request and request.toggle_runcall:
        runcall_cookie = request.cookies.get('pdb_runcall', False)
        if runcall_cookie:
            response.expireCookie('pdb_runcall')
            return Publish.call_object(object, args, request)
        else:
            response.setCookie('pdb_runcall', 1)

    if 'set_runcall_ignore' in request:
        if request.set_runcall_ignore:
            for ignore in request.set_runcall_ignore:
                response.appendCookie('runcall_ignore', ignore)
        else:
            response.expireCookie('runcall_ignore')

    if 'pdb_runcall' in request:
        if request.pdb_runcall:
            ignores = request.get('runcall_ignore', [])
            if ignores:
                ignores = ignores.split(':')
            for ignore in ignores:
                obj = resolveDottedName(ignore)
                if obj.im_func is getattr(object, 'im_func', None):
                    break
            else:
                return pdb.runcall(object, *args)
    return Publish.call_object(object, args, request)
def pdb_runcall(object, args, request):
    """If the request has the pdb_runcall key then we run the result
    of request traversal in the debugger.  Othwise, do it normally.

    A cookie for pdb_runcall may also be set or removed if the request
    has the toggle_runcall key."""
    response = request.response

    if 'toggle_runcall' in request and request.toggle_runcall:
        runcall_cookie = request.cookies.get('pdb_runcall', False)
        if runcall_cookie:
            response.expireCookie('pdb_runcall')
            return Publish.call_object(object, args, request)
        else:
            response.setCookie('pdb_runcall', 1)

    if 'set_runcall_ignore' in request:
        if request.set_runcall_ignore:
            for ignore in request.set_runcall_ignore:
                response.appendCookie('runcall_ignore', ignore)
        else:
            response.expireCookie('runcall_ignore')

    if 'pdb_runcall' in request:
        if request.pdb_runcall:
            ignores = request.get('runcall_ignore', [])
            if ignores:
                ignores = ignores.split(':')
            for ignore in ignores:
                obj = resolveDottedName(ignore)
                if obj.im_func is getattr(object, 'im_func', None):
                    break
            else:
                return pdb.runcall(object, *args)
    return Publish.call_object(object, args, request)
Beispiel #9
0
 def trace_wrapper(*args, **kwargs):
     gen = func(*args, **kwargs)
     try:
         while True:
             yield runcall(next, gen)
     except StopIteration:
         pass
Beispiel #10
0
def run(arg_parser, entry_function):
  arg_parser.add_argument("--pdb", action='store_true')
  arg_parser.add_argument("--ipdb", action='store_true')
  arg_parser.add_argument("--no_cuda", action='store_true')
  
  args = arg_parser.parse_args()
  
  import torch.cuda
  torch.cuda.disabled = args.no_cuda
  
  if args.ipdb:
    import ipdb
    ipdb.runcall(entry_function, args)
  elif args.pdb:
    import pdb
    pdb.runcall(entry_function, args)
  else:
    entry_function(args)
Beispiel #11
0
 def debug_func(self, *args, **kwargs):
     if not self.on_error:
         return runcall(self.func, *args, **kwargs)
     try:
         if has_ipdb:
             with launch_ipdb_on_exception():
                 return self.func(*args, **kwargs)
         else:
             return self.func(*args, **kwargs)
     except Exception as e:
         traceback.print_exc(file=sys.stderr)
         Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__).set_trace()
Beispiel #12
0
def run_in_pdb(func, args):
    def debug_signal_handler(signal, frame):
        import pdb
        pdb.set_trace()

    import signal
    signal.signal(signal.SIGINT, debug_signal_handler)

    import pdb as pdb_module

    import sys
    import traceback
    pdb = pdb_module.Pdb()
    while True:
        try:
            pdb.runcall(func, args)
            if pdb._user_requested_quit:
                break
            print("The program finished and will be restarted")
        except pdb_module.Restart:
            print("Restarting with arguments:")
            print("\t" + " ".join(sys.argv[1:]))
        except SystemExit:
            # In most cases SystemExit does not warrant a post-mortem session.
            print("The program exited via sys.exit(). Exit status: ", )
            print(sys.exc_info()[1])
        except SyntaxError:
            traceback.print_exc()
            sys.exit(1)
        except BaseException:
            traceback.print_exc()
            print("Uncaught exception. Entering post mortem debugging")
            print("Running 'cont' or 'step' will restart the program")
            t = sys.exc_info()[2]
            pdb.interaction(None, t)
            print(
                "Post mortem debugger finished. The program will be restarted")
Beispiel #13
0
def run(arg_parser, entry_function):
    arg_parser.add_argument("--pdb", action="store_true")
    arg_parser.add_argument("--ipdb", action="store_true")
    arg_parser.add_argument("--no_cuda", action="store_true")

    args = arg_parser.parse_args()

    import torch.cuda

    # todo: yuck
    torch.cuda.disabled = args.no_cuda

    def log(out_file):
        # subprocess.call("git rev-parse HEAD", shell=True, stdout=out_file)
        # subprocess.call("git --no-pager diff", shell=True, stdout=out_file)
        # out_file.write('\n\n')
        # out_file.write(' '.join(sys.argv))
        # out_file.write('\n\n')
        # json.dump(vars(args), out_file)
        out_file.write("\n\n")

    log(sys.stdout)
    # if 'save_dir' in vars(args) and args.save_dir:
    #     with open(os.path.join(args.save_dir, 'invoke.log'), 'w') as f:
    #         log(f)

    if args.ipdb:
        import ipdb

        ipdb.runcall(entry_function, args)
    elif args.pdb:
        import pdb

        pdb.runcall(entry_function, args)
    else:
        entry_function(args)
            rep_ind = find_nonzero_ind(col_list,row,True) #makes sure to not include the potential pivot row in the search but keeps the indexing constant with mtx
            multiple_factor = add_mult_row(mtx,mtx[row,col],mtx[rep_ind,col])
            mtx[rep_ind,:] += mtx[row,:]*multiple_factor
            col_list = list(mtx[:,col])
    pseudo_det *= grab_diag(mtx)

    
## trbl seems to be about two zeros next to each other, fixed by using a check against 


##ipdb.runcall(shortEF,trbl_makr)

def main ():
    global pseudo_det
    serious_trbl_mkrs = []
    runs = 200
    for i in range(runs):
        pseudo_det = 1
        trbl_mkr = Matrix(4,4,[random.randrange(1,100) if random.randrange(1,5) < 3 else 0 for num in range(16)])
        if shortEF(trbl_mkr) != trbl_mkr.rref()[0]:
            serious_trbl_mkrs.append(trbl_mkr)
        print(give_pseudo_det(),trbl_mkr.det())
    pprint(serious_trbl_mkrs)
    if len(serious_trbl_mkrs)/runs == 0.0:
        print('no incorrect RREFS')

if __name__ == "__main__":
    #main()
    ipdb.runcall(main)
    
Beispiel #15
0
 def trace_wrapper(*args, **kwargs):
     return runcall(func, *args, **kwargs)
from __future__ import division
import random
from sympy import *
x, y, z, t = symbols('x y z t')
k, m, n = symbols('k m n', integer=True)
f, g, h = symbols('f g h', cls=Function)
init_printing()
import ipdb

my_mat = Matrix(3,3,[random.randrange(100) for i in range(9)])
pprint(my_mat)
print("starting")
def split_mtx(mtx,row,col):
    mtx.row_del(row)
    mtx.col_del(col)
    return mtx
def recurse_det(mtx):
    if len(mtx) == 1:
        print("bottom of recurse")
        pprint(mtx)
        return mtx 
    else:
        print("stripping")
        pprint(mtx)
        return sum([mtx[0,i]*recurse_det(split_mtx(mtx.copy(),0,i))[0] if i%2 == 0 else
                    -mtx[0,i]*recurse_det(split_mtx(mtx.copy(),0,i))[0]
                    for i in range(mtx.cols)])
ipdb.runcall(recurse_det,my_mat)    
print(my_mat.det())
        
Beispiel #17
0
 def trace_wrapper(*args, **kwargs):
     return runcall(func, *args, **kwargs)
        col_list = list(cop[:,col])
        if try_cap < 0:
            return (row,col)
        if col_list.count(0) == cop.rows or col_list[row:].count(0) > cop.rows -1 -row:
            col +=1
            continue
        if cop[row,col] == 0 and col_list[row]!= col_list[row+1]:
                #cop = rolling_rep(cop,row)
                cop = target_swap(cop,row,col_list)
                pprint(cop)
                try_cap -=1
                continue
        if col_list[row:].count(0) == cop.rows -1 -row:
            col +=1
            row +=1
            continue
        else:
            
            rep_ind = find_nonzero_ind(col_list,row) #makes sure to not include the potential pivot row in the search but keeps the indexing constant with mtx
            multiple_factor = add_mult_row(cop,cop[row,col],cop[rep_ind,col])
            cop[rep_ind,:] += cop[row,:]*multiple_factor
            pprint(cop)
    return cop
trbl_makr = Matrix(4,8,[
0,0,0,0,25,0,0,54,4,0,0,0,71,52,82,0,0,0,0,0,61,51,0,0,0,0,0,14,37,77,85,0 
])
## trbl seems to be about two zeros next to each other, fixed by using a check against 


ipdb.runcall(shortRREF,trbl_makr)