Ejemplo n.º 1
0
 def add_content(self, more_content, no_docstring=False):
     if not is_mpd_running():
         return
         
     try:
         
         cls = self.object
         instance = cls(must_start_worker = False, must_handle_state = False)
         try:
             #instance.initialize_code()
             parameter_documentation = self.get_sphinx_doc_for_parameters(instance.parameters)
         finally:
             instance.stop()
             
     except Exception as ex:
         print(ex)
         return
         
     if self.analyzer:
         # prevent encoding errors when the file name is non-ASCII
         filename = str(self.analyzer.srcname)
         sourcename = '%s:docstring of %s' % (filename, self.fullname)
     else:
         sourcename = 'docstring of %s' % self.fullname
         
     encoding = self.analyzer  # and self.analyzer.encoding
     lines = prepare_docstring(force_decode(parameter_documentation, encoding))
     
     for i, line in enumerate(self.process_doc([lines,])):
             self.add_line(line, sourcename, i)
Ejemplo n.º 2
0
def slowtest_evrard_gadget():
    assert is_mpd_running()
    run_evrard([new_code("gadget")],
               10000,
               random_seed=12345,
               name_of_the_figure=os.path.join(get_path_to_results(),
                                               "evrard_test_gadget_10000.png"))
Ejemplo n.º 3
0
 def setUp(self):
     TestCase.setUp(self)
     from amuse.rfi.core import is_mpd_running
     self.assertTrue(
         is_mpd_running(),
         "MPICH2 mpd deamon process not running, cannot run this test as it requires MPI"
     )
Ejemplo n.º 4
0
 def add_content(self, more_content, no_docstring=False):
     if not is_mpd_running():
         return
         
     try:
         
         cls = self.object
         instance = cls(must_start_worker = False, must_handle_state = False)
         try:
             #instance.initialize_code()
             parameter_documentation = self.get_sphinx_doc_for_parameters(instance.parameters)
         finally:
             instance.stop()
             
     except Exception as ex:
         print ex
         return
         
     if self.analyzer:
         # prevent encoding errors when the file name is non-ASCII
         filename = unicode(self.analyzer.srcname,
                            sys.getfilesystemencoding(), 'replace')
         sourcename = u'%s:docstring of %s' % (filename, self.fullname)
     else:
         sourcename = u'docstring of %s' % self.fullname
         
     encoding = self.analyzer and self.analyzer.encoding
     lines = prepare_docstring(force_decode(parameter_documentation, encoding))
     
     for i, line in enumerate(self.process_doc([lines,])):
             self.add_line(line, sourcename, i)
Ejemplo n.º 5
0
def slowtest_evrard_gadget():
    assert is_mpd_running()
    run_evrard(
        [new_code("gadget")],
        10000,
        random_seed = 12345, 
        name_of_the_figure = os.path.join(get_path_to_results(), "evrard_test_gadget_10000.png")
    )
Ejemplo n.º 6
0
def test_simulate_small_cluster():
    """test_simulate_small_cluster
    This method is found by the testing framework and automatically
    run with all other tests. This method simulates
    a too small cluster, this is done to limit the testing time.
    """
    assert is_mpd_running()
    simulate_small_cluster(4, 4 | units.Myr)
Ejemplo n.º 7
0
def slowtest_evrard_compare():
    assert is_mpd_running()
    global labels
    labels = fi_gadget_labels
    run_evrard([new_code("fi"), new_code("gadget")],
               10000,
               random_seed=12345,
               name_of_the_figure=os.path.join(
                   get_path_to_results(), "evrard_test_compare_10000.png"))
Ejemplo n.º 8
0
def test_simulate_one_star():
    assert is_mpd_running()
    code = new_code("sse", 1)
    test_results_path = get_path_to_results()
    output_file = os.path.join(test_results_path, "HR_evolution_tracks.png")
    simulate_evolution_tracks(
        code,
        [20.0] | units.MSun,
        name_of_the_figure=output_file,
    )
Ejemplo n.º 9
0
def test_simulate_one_star():
    assert is_mpd_running()
    code = new_code("sse", 1)
    test_results_path = get_path_to_results()
    output_file = os.path.join(test_results_path, "HR_evolution_tracks.png")
    simulate_evolution_tracks(
        code,
        [20.0] | units.MSun,
        name_of_the_figure=output_file, 
    )
Ejemplo n.º 10
0
def slowtest_evrard_compare():
    assert is_mpd_running()
    global labels
    labels = fi_gadget_labels
    run_evrard(
        [new_code("fi"), new_code("gadget")],
        10000,
        random_seed = 12345, 
        name_of_the_figure = os.path.join(get_path_to_results(), "evrard_test_compare_10000.png")
    )
Ejemplo n.º 11
0
def test_simulate_small_cluster():
    """test_simulate_small_cluster
    This method is found by the testing framework and automatically
    run with all other tests. This method simulates
    a too small cluster, this is done to limit the testing time.
    """
    assert is_mpd_running()
    test_results_path = get_path_to_results()
    output_file = os.path.join(test_results_path, "test-2.svg")
    simulate_small_cluster(4, 4 | units.Myr, name_of_the_figure=output_file)
Ejemplo n.º 12
0
def test_simulate_small_cluster():
    """test_simulate_small_cluster
    This method is found by the testing framework and automatically
    run with all other tests. This method simulates
    a too small cluster, this is done to limit the testing time.
    """
    assert is_mpd_running()
    test_results_path = get_path_to_results()
    output_file = os.path.join(test_results_path, "test-2.svg")
    simulate_small_cluster(4, 4 | units.Myr,
                           name_of_the_figure=output_file)
Ejemplo n.º 13
0
def test_simulate_short():
    assert is_mpd_running()
    code = new_code("sse", 100)

    test_results_path = get_path_to_results()
    output_file = os.path.join(test_results_path, "cluster_HR_diagram.png")

    simulate_stellar_evolution(code,
                               number_of_stars=100,
                               end_time=2.0 | units.Myr,
                               name_of_the_figure=output_file)
Ejemplo n.º 14
0
def test_simulate_short():
    assert is_mpd_running()
    code = new_code("sse", 100)

    test_results_path = get_path_to_results()
    output_file = os.path.join(test_results_path, "cluster_HR_diagram.png")

    simulate_stellar_evolution(
        code,
        number_of_stars=100,
        end_time=2.0 | units.Myr,
        name_of_the_figure=output_file
    )
Ejemplo n.º 15
0
def main():
    assert is_mpd_running()
    seed = None

    nstars = 128
    if len(sys.argv) > 1:
        stars = int(sys.argv[1])
    with_units = len(sys.argv) > 2

    if not with_units:
        mass_unit = nbody_system.mass
        length_unit = nbody_system.length
    else:
        mass_unit = units.MSun
        length_unit = units.parsec

    m_min = 0.1 | mass_unit
    m_max = 100 | mass_unit
    alpha = -2.35

    r_vir = 1 | length_unit
    masses = new_salpeter_mass_distribution(nstars, m_min, m_max, alpha)
    m_tot = masses.sum()

    if not with_units:
        convert_nbody = None
        masses /= m_tot.value_in(nbody_system.mass)  # scale to unit mass
        m_tot = 1 | nbody_system.mass
    else:
        convert_nbody = nbody_system.nbody_to_si(m_tot, r_vir)
        convert_nbody.set_as_default()
        print m_tot

    stars = new_plummer_model(nstars, convert_nbody, random_state=seed)
    stars.mass = masses

    LagrangianRadii(stars, verbose=True)
Ejemplo n.º 16
0
def test_cloud():
    if not is_mpd_running():
        return
    run_cloud(1000)
Ejemplo n.º 17
0
def test_evrard():
    if not is_mpd_running():
        return
    run_evrard(64)
Ejemplo n.º 18
0
        default=None,
        dest="cacheDir",
        help="Use/write cache from directory"
    )     
    result.add_option(
        "-p",
        "--plot_file",
        type="string",
        default="HR_evolution_tracks.png",
        dest="plot_filename",
        help="Name of the file to plot to"
    )
    return result

if __name__ == '__main__':
    if not is_mpd_running():
        print "There is no mpd server running. Please do 'mpd &' first."
        sys.exit()
    parser = new_commandline_option_parser()
    (options, arguments) = parser.parse_args()
    if arguments:
        parser.error("unknown arguments '{0}'".format(arguments))
    mass_list = [0.5, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0] | units.MSun
    
    code = new_code(options.code, len(mass_list))
    if not (options.cacheDir is None):
        print "Using cache directory: %s" % (options.cacheDir)
# As a special case, we use caching of the underlying models instead of the model output for EVtwin2SSE
        if (options.code == "evtwin2sse"):
            code.cache_underlying_models(options.cacheDir)
        else:
Ejemplo n.º 19
0
            infile = a
        elif o == "-g":
            use_gpu = 0
        elif o == "-G":
            use_gpu = 0
            gpu_worker = 0
        elif o == "-i":
            gpu_id = int(a)
        elif o == "-n":
            N = int(a)
        elif o == "-s":
            random_seed = int(a)
        elif o == "-t":
            t_end = float(a) | nbody_system.time
        elif o == "-w":
            n_workers = int(a)
        else:
            print "unexpected argument", o

    if random_seed <= 0:
        numpy.random.seed()
        random_seed = numpy.random.randint(1, pow(2, 31) - 1)
    numpy.random.seed(random_seed)
    print "random seed =", random_seed

    #os.system('env')

    assert is_mpd_running()
    run_ph4(infile, N, t_end, delta_t, n_workers, use_gpu, gpu_worker, gpu_id,
            accuracy_parameter, softening_length, manage_encounters)
Ejemplo n.º 20
0
def test_cloud():
    if not is_mpd_running():
        return
    run_cloud(1000)
Ejemplo n.º 21
0
 def setUp(self):
     TestCase.setUp(self)
     from amuse.rfi.core import is_mpd_running
     self.assertTrue(is_mpd_running(), "MPICH2 mpd deamon process not running, cannot run this test as it requires MPI")
Ejemplo n.º 22
0
def test_evrard():
    if not is_mpd_running():
        return
    run_evrard(64)
Ejemplo n.º 23
0
        dest="cacheDir",
        help="Use/write cache from directory"
    )
    result.add_option(
        "-p",
        "--plot_file",
        type="string",
        default="HR_evolution_tracks.png",
        dest="plot_filename",
        help="Name of the file to plot to"
    )
    return result


if __name__ == '__main__':
    if not is_mpd_running():
        print("There is no mpd server running. Please do 'mpd &' first.")
        sys.exit()
    parser = new_commandline_option_parser()
    (options, arguments) = parser.parse_args()
    if arguments:
        parser.error("unknown arguments '{0}'".format(arguments))
    mass_list = [0.5, 1.0, 2.0, 5.0, 10.0, 20.0, 30.0] | units.MSun

    code = new_code(options.code, len(mass_list))
    if not (options.cacheDir is None):
        print("Using cache directory: %s" % (options.cacheDir))
        # As a special case, we use caching of the underlying models instead of
        # the model output for EVtwin2SSE
        if (options.code == "evtwin2sse"):
            code.cache_underlying_models(options.cacheDir)
Ejemplo n.º 24
0
                               0)
    kep.stop()

if __name__ == '__main__':

    mass = 1 | nbody_system.mass
    semi = 1 | nbody_system.length
    ecc = 0.5 
    time = 5.0 | nbody_system.time

    try:
        opts, args = getopt.getopt(sys.argv[1:], "a:e:m:t:")
    except getopt.GetoptError, err:
        print str(err)
        sys.exit(1)

    for o, a in opts:
        if o == "-a":
            semi = float(a) | nbody_system.length
        elif o == "-e":
            ecc = float(a)
        elif o == "-m":
            time = float(a) | nbody_system.mass
        elif o == "-t":
            time = float(a) | nbody_system.time
        else:
            print "unexpected argument", o

    assert is_mpd_running()
    run_kepler(mass, semi, ecc, time)