def redistill(distillate_filename, out_filename, expected_dps=60, newton_steps=7, min_model_digits=None): """Second-distills a distillate.""" if mpmath.mp.dps < expected_dps: raise RuntimeError( 'Precision setting for mpmath is below the expected dps ' 'for this calculation: %s < %s' % (mpmath.mp.dps, expected_dps)) # Tries to find out if there are further opportunities that reduce the number # of parameters which have been missed in 1st distillation, and if so, # performs the corresponding reduction. # In any case, adds basic information about physics. distillate_model = read_distillate_model(distillate_filename) v70 = v70_from_model(distillate_model) if expected_dps > 15: sinfo0 = scalar_sector_mpmath.mpmath_scalar_manifold_evaluator(v70) else: sinfo0 = scalar_sector.numpy_scalar_manifold_evaluator(v70) threshold_deviation = (max(3 * sinfo0.stationarity, 1e-7) if expected_dps >= 40 else 1e-3) # First-distillation produced a high-accuracy form of the numerical # solution, so we should use a stricter check here. def still_good(v70_trial): sinfo = scalar_sector.numpy_scalar_manifold_evaluator(v70_trial) return (abs(sinfo0.potential - sinfo.potential) < threshold_deviation and sinfo.stationarity < threshold_deviation) # This is strongly expected to work, given that we already had highly # accurate data. low_dim_model_take2 = iter(find_simple_low_dimensional_model( [v70], min_digits=max(3, min_model_digits or int( -mpmath.log(sinfo0.stationarity, 10)) // 2 - 2), still_good=still_good)).next() if len(low_dim_model_take2.params) < len(distillate_model.params): print('Note: Could further reduce the number of model parameters ' '({} -> {}).'.format(distillate_model.params, low_dim_model_take2.params)) model_take2, mdnewton_ok = distill_model( low_dim_model_take2, newton_steps=newton_steps, still_good=still_good, target_digits_position=expected_dps) v70_accurate = v70_from_model(model_take2) sinfo_accurate = scalar_sector_mpmath.mpmath_scalar_manifold_evaluator( v70_accurate) stationarity = sinfo_accurate.stationarity log10_stationarity = math.floor(mpmath.log(stationarity, 10)) approx_stationarity_str = ( '%.3fe%d' % (float(stationarity * mpmath.mpf(10)**(-log10_stationarity)), log10_stationarity)) with open(out_filename, 'w') as h: write_model(h, model_take2, dict(mdnewton_ok=mdnewton_ok, potential=str(sinfo_accurate.potential), stationarity=approx_stationarity_str))
def process_raw_v70(raw_v70, work_dir, newton_steps=4, skip_gradient_descent=False): """Processes a raw 70-vector.""" model, _ = distillation.distill(raw_v70, target_digits_position=25, newton_steps=newton_steps, skip_gradient_descent=skip_gradient_descent) v70 = distillation.v70_from_model(model) sinfo = scalar_sector_mpmath.mpmath_scalar_manifold_evaluator(v70) tag = scalar_sector_tensorflow.S_id(sinfo.potential) data_dir = os.path.join(work_dir, tag) os.makedirs(data_dir, exist_ok=True) location_filename = os.path.join(data_dir, 'location.pytxt') with open(location_filename, 'wt') as out_handle: distillation.write_model(out_handle, model, dict( potential=str(sinfo.potential), stationarity=str(sinfo.stationarity))) physics = distillation.explain_physics(location_filename) with open(os.path.join(data_dir, 'physics.pytxt'), 'wt') as out_handle: # The output file provides angular momenta and charges for the # mass eigenstates. out_handle.write(pprint.pformat(physics)) generate_symmetry_info([tag], directory=work_dir) print('\n=== Done. Data is in %s/*.pytxt ===\n' % data_dir)
def generate_some_solutions(): # Let us first get some critical points. print('\n=== Scanning for solutions ===\n') # We pause for a second after each such "stage" message to give the user # an opportunity to see what is currently going on, amongst all the # messages flying by that come from optimizers whose output can not # be suppressed. time.sleep(1) # This scans for solutions and writes the result to the file # given as last arg. makedirs(work_dir) # A scale of 0.2 for the initial vector only probes a small region # "near the origin". We do not expect to find difficult-to-analyze solutions # there. A more appropriate starting value for a deeper search would be # e.g. 2.0. extrema = scan_for_solutions( 1, 0.2, 10, os.path.join(work_dir, 'SCANS.pytxt')) tags = sorted(extrema) print('\n=== Found: %s ===\n' % tags) time.sleep(1) # For this demo, we only process the very first one. # First, canonicalize. v70_last_extremum = numpy.array(extrema[tags[-1]][0][-1]) print('\n=== Distilling (this will take a while)... ===\n') time.sleep(1) distilled, _ = distillation.distill(v70_last_extremum, target_digits_position=40) out_dir = os.path.join(work_dir, tags[-1]) makedirs(out_dir) v70 = distillation.v70_from_model(distilled) sinfo = scalar_sector_mpmath.mpmath_scalar_manifold_evaluator(v70) with open(os.path.join(out_dir, 'location.pytxt'), 'w') as out_handle: distillation.write_model(out_handle, distilled, dict( potential=str(sinfo.potential), stationarity=str(sinfo.stationarity)))
def explain_physics(distillate_filename): """Explains residual SUSY and particle masses for a solution.""" distillate = read_distillate(distillate_filename) model = get_distillate_model(distillate) v70 = v70_from_model(model) sinfo = scalar_sector_mpmath.mpmath_scalar_manifold_evaluator(v70) a1 = sinfo.a1 a2 = sinfo.a2 gravitinos = get_gravitino_mass_eigenstates_from_a1(a1, sinfo.potential) fermions = get_fermion_mass_eigenstates_from_a2(a2, sinfo.potential) scalar_mass_matrix = get_scalar_mass_matrix(v70) scalars = get_scalar_mass_eigenstates_from_mass_matrix(scalar_mass_matrix) return dict(potential=str(sinfo.potential), susy=get_susy_from_a2(a2), gravitinos=gravitinos, fermions=fermions, scalars=scalars)
def f_off(*model_vec): v70 = numpy.dot(low_dimensional_model.v70_from_params, numpy.array(model_vec, dtype=mpmath.mpf)) sinfo = scalar_sector_mpmath.mpmath_scalar_manifold_evaluator(v70) return tuple(sinfo.grad_potential)