def __repr__(cls): rows = [['Pos', 'Match Type', 'Condition', 'Action Name / Action Description', 'Stop']] for i, r in enumerate(cls.rules): rows.append([str(i), r.condition_type, r.condition_description, r.action_description]) return format_table(rows)
def __repr__(cls): rows = [['Pos', 'Match Type', 'Condition', 'Action Name / Action Description', 'Stop']] for i, r in enumerate(cls.rules): for ii in range(r.num_rules): rows.append(['' if ii else str(i), r.condition_type, r.condition_description, '' if ii else r.action_description]) r = r.next_rule return format_table(rows)
def __repr__(cls): rows = [[ 'Pos', 'Match Type', 'Condition', 'Action Name / Action Description', 'Stop' ]] for i, r in enumerate(cls.rules): rows.append([ str(i), r.condition_type, r.condition_description, r.action_description ]) return format_table(rows)
def hapod_demo(args): args['--grid'] = int(args['--grid']) args['--nt'] = int(args['--nt']) args['--omega'] = float(args['--omega']) args['--procs'] = int(args['--procs']) args['--snap'] = int(args['--snap']) args['--threads'] = int(args['--threads']) args['TOL'] = float(args['TOL']) args['DIST'] = int(args['DIST']) args['INC'] = int(args['INC']) assert args['--procs'] == 0 or args['--threads'] == 0 tol = args['TOL'] omega = args['--omega'] executor = ProcessPoolExecutor(args['--procs']) if args['--procs'] > 0 else \ ThreadPoolExecutor(args['--threads']) if args['--threads'] > 0 else \ None p = burgers_problem_2d() d, data = discretize_instationary_fv(p, grid_type=RectGrid, diameter=np.sqrt(2)/args['--grid'], nt=args['--nt']) U = d.solution_space.empty() for mu in d.parameter_space.sample_randomly(args['--snap']): U.append(d.solve(mu)) tic = time() pod_modes = pod(U, l2_err=tol * np.sqrt(len(U)), product=d.l2_product, check=False)[0] pod_time = time() - tic tic = time() dist_modes = dist_vectorarray_hapod(args['DIST'], U, tol, omega, product=d.l2_product, executor=executor)[0] dist_time = time() - tic tic = time() inc_modes = inc_vectorarray_hapod(args['INC'], U, tol, omega, product=d.l2_product)[0] inc_time = time() - tic print('Snapshot matrix: {} x {}'.format(U.dim, len(U))) print(format_table([ ['Method', 'Error', 'Modes', 'Time'], ['POD', np.linalg.norm(d.l2_norm(U-pod_modes.lincomb(d.l2_product.apply2(U, pod_modes)))/np.sqrt(len(U))), len(pod_modes), pod_time], ['DIST HAPOD', np.linalg.norm(d.l2_norm(U-dist_modes.lincomb(d.l2_product.apply2(U, dist_modes)))/np.sqrt(len(U))), len(dist_modes), dist_time], ['INC HAPOD', np.linalg.norm(d.l2_norm(U-inc_modes.lincomb(d.l2_product.apply2(U, inc_modes)))/np.sqrt(len(U))), len(inc_modes), inc_time]] ))
def print_defaults(import_all=True, shorten_paths=2): """Print all |default| values set in pyMOR. Parameters ---------- import_all While :func:`print_defaults` will always print all defaults defined in loaded configuration files or set via :func:`set_defaults`, default values set in the function signature can only be printed after the modules containing these functions have been imported. If `import_all` is set to `True`, :func:`print_defaults` will therefore first import all of pyMOR's modules, to provide a complete lists of defaults. shorten_paths Shorten the paths of all default values by `shorten_paths` components. The last two path components will always be printed. """ if import_all: _default_container.import_all() keys = ([], []) values = ([], []) comments = ([], []) for k in sorted(_default_container.keys()): v, c, i = _default_container.get(k) k_parts = k.split('.') if len(k_parts) >= shorten_paths + 2: keys[int(i)].append('.'.join(k_parts[shorten_paths:])) else: keys[int(i)].append('.'.join(k_parts)) values[int(i)].append(repr(v)) comments[int(i)].append(c) key_string = 'path (shortened)' if shorten_paths else 'path' for i, (ks, vls, cs) in enumerate(zip(keys, values, comments)): description = 'defaults not affecting state id calculation' if i else 'defaults affecting state id calcuation' rows = [[key_string, 'value', 'source']] + list(zip(ks, vls, cs)) print(format_table(rows, title=description)) if not i: print() print() print()
def hapod_demo(args): args['--grid'] = int(args['--grid']) args['--nt'] = int(args['--nt']) args['--omega'] = float(args['--omega']) args['--procs'] = int(args['--procs']) args['--snap'] = int(args['--snap']) args['--threads'] = int(args['--threads']) args['TOL'] = float(args['TOL']) args['DIST'] = int(args['DIST']) args['INC'] = int(args['INC']) assert args['--procs'] == 0 or args['--threads'] == 0 tol = args['TOL'] omega = args['--omega'] executor = ProcessPoolExecutor(args['--procs']) if args['--procs'] > 0 else \ ThreadPoolExecutor(args['--threads']) if args['--threads'] > 0 else \ None p = burgers_problem_2d() m, data = discretize_instationary_fv(p, grid_type=RectGrid, diameter=np.sqrt(2) / args['--grid'], nt=args['--nt']) U = m.solution_space.empty() for mu in m.parameter_space.sample_randomly(args['--snap']): U.append(m.solve(mu)) tic = time() pod_modes = pod(U, l2_err=tol * np.sqrt(len(U)), product=m.l2_product, check=False)[0] pod_time = time() - tic tic = time() dist_modes = dist_vectorarray_hapod(args['DIST'], U, tol, omega, product=m.l2_product, executor=executor)[0] dist_time = time() - tic tic = time() inc_modes = inc_vectorarray_hapod(args['INC'], U, tol, omega, product=m.l2_product)[0] inc_time = time() - tic print(f'Snapshot matrix: {U.dim} x {len(U)}') print( format_table([ ['Method', 'Error', 'Modes', 'Time'], [ 'POD', np.linalg.norm( m.l2_norm(U - pod_modes.lincomb( m.l2_product.apply2(U, pod_modes))) / np.sqrt(len(U))), len(pod_modes), pod_time ], [ 'DIST HAPOD', np.linalg.norm( m.l2_norm(U - dist_modes.lincomb( m.l2_product.apply2(U, dist_modes))) / np.sqrt(len(U))), len(dist_modes), dist_time ], [ 'INC HAPOD', np.linalg.norm( m.l2_norm(U - inc_modes.lincomb( m.l2_product.apply2(U, inc_modes))) / np.sqrt(len(U))), len(inc_modes), inc_time ] ]))
def main( tol: float = Argument(..., help='Prescribed mean l2 approximation error.'), dist: int = Argument(..., help='Number of slices for distributed HAPOD.'), inc: int = Argument(..., help='Number of steps for incremental HAPOD.'), grid: int = Option(60, help='Use grid with (2*NI)*NI elements.'), nt: int = Option(100, help='Number of time steps.'), omega: float = Option(0.9, help='Parameter omega from HAPOD algorithm.'), procs: int = Option( 0, help='Number of processes to use for parallelization.'), snap: int = Option(20, help='Number of snapshot trajectories to compute.'), threads: int = Option( 0, help='Number of threads to use for parallelization.'), ): """Compression of snapshot data with the HAPOD algorithm from [HLR18].""" assert procs == 0 or threads == 0 executor = ProcessPoolExecutor(procs) if procs > 0 else \ ThreadPoolExecutor(threads) if threads > 0 else \ None p = burgers_problem_2d() m, data = discretize_instationary_fv(p, grid_type=RectGrid, diameter=np.sqrt(2) / grid, nt=nt) U = m.solution_space.empty() for mu in p.parameter_space.sample_randomly(snap): U.append(m.solve(mu)) tic = time.perf_counter() pod_modes = pod(U, l2_err=tol * np.sqrt(len(U)), product=m.l2_product)[0] pod_time = time.perf_counter() - tic tic = time.perf_counter() dist_modes = dist_vectorarray_hapod(dist, U, tol, omega, product=m.l2_product, executor=executor)[0] dist_time = time.perf_counter() - tic tic = time.perf_counter() inc_modes = inc_vectorarray_hapod(inc, U, tol, omega, product=m.l2_product)[0] inc_time = time.perf_counter() - tic print(f'Snapshot matrix: {U.dim} x {len(U)}') print( format_table([ ['Method', 'Error', 'Modes', 'Time'], [ 'POD', np.linalg.norm( m.l2_norm(U - pod_modes.lincomb( m.l2_product.apply2(U, pod_modes))) / np.sqrt(len(U))), len(pod_modes), pod_time ], [ 'DIST HAPOD', np.linalg.norm( m.l2_norm(U - dist_modes.lincomb( m.l2_product.apply2(U, dist_modes))) / np.sqrt(len(U))), len(dist_modes), dist_time ], [ 'INC HAPOD', np.linalg.norm( m.l2_norm(U - inc_modes.lincomb( m.l2_product.apply2(U, inc_modes))) / np.sqrt(len(U))), len(inc_modes), inc_time ] ]))