Example #1
0
 def run_simulation(self, simulation_input):
     sim = self.init_rebound_simulation(simulation_input)
     feature_classifier_model = FeatureClassifier()
     deep_regressor_model = DeepRegressor()
     stability_probability = feature_classifier_model.predict_stable(sim)
     median, lower, upper = deep_regressor_model.predict_instability_time(sim, samples=10000)
     return {"star_mass": simulation_input.star_mass,
             "periods": ",".join([str(planet_period) for planet_period in simulation_input.planet_periods]),
             "masses": ",".join([str(mass_value) for mass_value in simulation_input.mass_arr]),
             "inclinations": ",".join([str(ecc_value) for ecc_value in simulation_input.inc_arr]),
             "eccentricities": ",".join([str(ecc_value) for ecc_value in simulation_input.ecc_arr]),
             "arg_periastron": ",".join([str(ecc_value) for ecc_value in simulation_input.omega_arr]),
             "stability_probability": stability_probability, "median_expected_instability_time": median}
Example #2
0
 def run(self, planet_params):
     sim = rebound.Simulation()
     sim.integrator = "whfast"
     sim.ri_whfast.safe_mode = 0
     sim.dt = 1e-2
     sim.add(m=1.0)
     for planet_param in planet_params:
         sim.add(m=self.mass_from_radius(planet_param.r) * 0.000003003 /
                 self.star_mass,
                 P=planet_param.P,
                 e=planet_param.e,
                 omega=planet_param.omega)
     #sim.status()
     sim.move_to_com()
     model = FeatureClassifier()
     print("SPOCK=" + str(model.predict_stable(sim)))
				#### scale the satellite masses to the planet mass, and the semimajor axis to that of the innermost satellite.
				sim.add(m=moon_dict[moon]['m']/planet_mass_kg, a=moon_dict[moon]['a']/moon_dict['I']['a'], e=moon_dict[moon]['e'], pomega=moon_dict[moon]['pomega'], f=moon_dict[moon]['f'], inc=moon_dict[moon]['inc'], hash=moon)
				#print('sim mass = ', moon_dict[moon]['m']/planet_mass_kg)
				#print('sim sma = ', moon_dict[moon]['a']/moon_dict['I']['a'])
				#print(' ')

			elif use_spock_scaling == 'n':
				sim.add(m=moon_dict[moon]['m'], a=moon_dict[moon]['a'], e=moon_dict[moon]['e'], pomega=moon_dict[moon]['pomega'], f=moon_dict[moon]['f'], inc=moon_dict[moon]['inc'], hash=moon)

		sim.move_to_com() ### critical step!
		sim.init_megno() #### for testing two-moon stability.
		exit_distance = Plan_Rhill_meters / moon_dict['I']['a'] #### the Hill sphere, in units of the first moon's semimajor axis.
		sim.exit_max_distance = exit_distance 

		try:
			stability_probability = stability_model.predict_stable(sim)
			print('SPOCK stability probability: ', stability_probability)

		except KeyboardInterrupt:
			keep_going = 'n'
			break

		except Exception:
			print('CANNOT RUN SPOCK ON SYSTEMS WITH FEWER THAN THREE MOONS.')
			keep_going = 'y'
			stability_probability = np.nan 

		if (stability_probability < 0.5) and (enforce_stability == 'y'):
			print('SPOCK PREDICTS UNSTABLE SYSTEM (P_stable = '+str(stability_probability 	)+'. CONTINUE.')
			print('# created so far = ', nsystems_made)
			nscrapped += 1
Example #4
0
class TestClassifier(unittest.TestCase):
    def setUp(self):
        self.model = FeatureClassifier()
    
    def test_list(self):
        stable_target = [0, 0, 0, 0.7]
        stable = self.model.predict_stable([hyperbolicsim(), escapesim(), unstablesim(), longstablesim()])
        self.assertEqual(stable[0], 0)
        self.assertEqual(stable[1], 0)
        self.assertEqual(stable[2], 0)
        self.assertGreater(stable[3], 0.7) 
    
    def test_sim_unchanged(self):
        sim = rebound.Simulation()
        sim.add(m=1.)
        sim.add(m=1.e-5, P=1.)
        sim.add(m=1.e-5, P=2.)
        sim.add(m=1.e-5, P=3.)
        sim.integrate(1.2)
        x0 = sim.particles[1].x
        p1 = self.model.predict_stable(sim)
        self.assertEqual(sim.particles[1].x, x0)

    def test_repeat(self):
        sim = rebound.Simulation()
        sim.add(m=1.)
        sim.add(m=1.e-5, P=1.)
        sim.add(m=1.e-5, P=2.)
        sim.add(m=1.e-5, P=3.)
        p1 = self.model.predict_stable(sim)
        p2 = self.model.predict_stable(sim)
        self.assertEqual(p1, p2)

    def test_same_trajectory(self):
        sim = longstablesim()
        init_sim_parameters(sim)
        _, _ = get_tseries(sim, (1e4, 80, [[1,2,3]]))
        x1 = sim.particles[1].x

        sim = longstablesim()
        nbody = NbodyRegressor()
        nbody.predict_stable(sim, tmax=1e4, archive_filename='temp.bin', archive_interval=1.e4)
        sa = rebound.SimulationArchive('temp.bin')
        sim = sa[-1]
        x2 = sim.particles[1].x
        self.assertAlmostEqual(x1, x2, delta=1.e-5)
   
    # when chaotic realization matters, probs will vary more (eg t_inst=2e4)
    def test_galilean_transformation(self):
        sim = longstablesim()
        sim.move_to_com()
        p_com = self.model.predict_stable(sim)

        sim = longstablesim()
        for p in sim.particles:
            p.vx += 1000
        p_moving = self.model.predict_stable(sim)
        self.assertAlmostEqual(p_com, p_moving, delta=1.e-2)
   
    def test_rescale_distances(self):
        sim = longstablesim()
        p0 = self.model.predict_stable(sim)

        sim = longstablesim()
        sim = rescale(sim, dscale=1e10, tscale=1, mscale=1)
        p1 = self.model.predict_stable(sim)
        self.assertAlmostEqual(p0, p1, delta=1.e-2)
    
    def test_rescale_times(self):
        sim = longstablesim()
        p0 = self.model.predict_stable(sim)

        sim = longstablesim()
        sim = rescale(sim, dscale=1, tscale=1e10, mscale=1)
        p1 = self.model.predict_stable(sim)
        self.assertAlmostEqual(p0, p1, delta=1.e-1)

    def test_rescale_masses(self):
        sim = longstablesim()
        p0 = self.model.predict_stable(sim)

        sim = longstablesim()
        sim = rescale(sim, dscale=1, tscale=1, mscale=1e10)
        p1 = self.model.predict_stable(sim)
        self.assertAlmostEqual(p0, p1, delta=1.e-2)
    
    def test_hyperbolic(self):
        sim = hyperbolicsim()
        self.assertEqual(self.model.predict_stable(sim), 0)
    
    def test_escape(self):
        sim = escapesim()
        self.assertEqual(self.model.predict_stable(sim), 0)
    
    def test_unstable_in_short_integration(self):
        sim = unstablesim()
        self.assertEqual(self.model.predict_stable(sim), 0)
    
    def test_solarsystem(self):
        sim = solarsystemsim()
        self.assertGreater(self.model.predict_stable(sim), 0.7)
    
    def test_stable(self):
        sim = longstablesim()
        self.assertGreater(self.model.predict_stable(sim), 0.7)