Example #1
0
    def pid(self):
        """Finds the process id for a currently running char instance."""
        if self.env['options'].LOCAL:
            rflag = ''
            spout = subprocess.check_output("qstat -u {0}| grep {1}".format(os.getlogin(), self.n_code.run_str), shell=True) 
        else:
            rflag = 'Remote '
            try:
                spout = subprocess.check_output("ssh {rc.user}@{rc.url} 'qstat -u {rc.user}'".format(rc=rc), shell=True)
            except NameError:
                if 0 < self.env['verbosity']:
                    print(failure(remote_err_msg))

        spout = spout.split('\n')
        if len(spout) < 2:
            if 0 < self.env['verbosity']:
                print(message("{0}Process Not Running.".format(rflag)))
            raise SystemExit

        spout = spout[-2].split()
        self.pid = spout[0].partition('.')[0]
        self.prt = spout[-1]

        if 0 < self.env['verbosity']:
            print(message("{0}Process ID: {1}".format(rflag, self.pid)))
            print(message("{0}Process Runtime: {1} min.".format(rflag, self.prt)))

        raise SystemExit
Example #2
0
    def run_remotely(self):
        """Runs the transport calculation on a remote machine"""
        if 0 < self.env['verbosity']:
            print(message("Copying files to remote server."))

        rs = self.env['run_script']
        rc = self.env['remote_connection']

        try:
            # Make remote directory, if it isn't already there
            rc.run("mkdir -p {rc.dir}".format(rc=rc))

            # Remove the current contents of the remote directory        
            rc.run("rm -r {rc.dir}*".format(rc=rc))

            # Put all appropriate files in reomte dir
            rc.put(rs, rc.dir + rs)
            for inputfile in self.n_code.place_remote_files:
                print(inputfile)
                rc.put(inputfile, rc.dir + inputfile)

            # Run char
            rc.run("source /etc/profile; cd {rc.dir}; ./{rs} > run.log 2>&1 &".format(rc=rc, 
                                                                                      rs=rs))
            if 0 < self.env['verbosity']:
                print(message("Running transport code remotely."))

        except NameError:
            if 0 < self.env['verbosity']:
                print(failure(remote_err_msg))

        # My work here is done
        raise SystemExit
Example #3
0
    def pid(self):
        """Finds the process id for a currently running char instance."""
        if self.env['options'].LOCAL:
            rflag = ''
            spout = subprocess.check_output("ps ux | grep {0}".format(self.n_code.run_str), shell=True) 
        else:
            rflag = 'Remote '
            try:
                spout = subprocess.check_output("ssh {rc.user}@{rc.url} 'ps ux | grep {0}'".format(
                                                self.n_code.run_str, rc=self.env.remote_connection), 
                                                shell=True) 
            except NameError:
                if 0 < self.env['verbosity']:
                    print(failure(remote_err_msg))

        spout = spout.split('\n')[:-1]
        if len(spout) < 1:
            if 0 < self.env['verbosity']:
                print(message("{0}Process Not Running.".format(rflag)))
            raise SystemExit

        self.pid = spout[0].split()[1]
        self.prt = spout[0].split()[9]

        if 0 < self.env['verbosity']:
            print(message("{0}Process ID: {1}".format(rflag, self.pid)))
            print(message("{0}Process Runtime: {1} min.".format(rflag, self.prt)))

        raise SystemExit
Example #4
0
    def kill(self):
        """Kills the currently running char process."""
        # Grab the pid
        try:
            self.pid()
        except SystemExit:
            pass

        # Kill the process
        if self.env['options'].LOCAL:
            rflag = ''
            spout = subprocess.check_output("qdel {0}".format(self.pid), shell=True)
        else:
            rflag = 'Remote '
            spout = '\n'
            self.env['remote_connection'].run("qdel {0}".format(self.pid))
            self.env['remote_connection'].run("cluster-kill sss-dev")

        spout = spout.split('\n')[:-1]

        if 0 < self.env['verbosity']:
            print(spout)
            print(message("{0}Process Killed.".format(rflag)))

        raise SystemExit
Example #5
0
    def run_locally(self):
        """Runs the transport calculation on the local machine."""
        t1 = time.time()
        subprocess.call("./{0}".format(self.env['run_script']), shell=True)
        t2 = time.time()

        # Report times
        time_msg = "{0:.3G}".format((t2-t1)/60.0)
        self.env['logger'].info("Transport executed in {0} minutes.".format(time_msg))
        if 0 < self.env['verbosity']:
            print(message("\nTransport executed in {0} minutes.\n".format(time_msg)))
Example #6
0
    def fetch(self):
        """Fetches files from remote server."""
        if 0 < self.env['verbosity']:
            print(message("Fetching files from remote server."))

        try:
            for outputfile in self.n_code.fetch_remote_files:
                self.env['remote_connection'].get(self.env.remote_connection.dir + outputfile, ".")
        except NameError:
            if 0 < self.env['verbosity']:
                print(failure(remote_err_msg))

        raise SystemExit
Example #7
0
    def kill(self):
        """Kills the currently running char process."""
        # Grab the pid
        try:
            self.pid()
        except SystemExit:
            pass

        # Kill the process
        if self.env.LOCAL:
            rflag = ''
            spout = subprocess.check_output("kill {0}".format(self.pid), shell=True)
        else:
            rflag = 'Remote '
            spout = '\n'
            self.env.remote_connection.run("kill {0}".format(self.pid))

        spout = spout.split('\n')[:-1]

        if 0 < self.env.VERBOSE:
            print(spout)
            print(message("{0}Process Killed.".format(rflag)))

        raise SystemExit
Example #8
0
def test_message():
    if os.name is 'posix':
        assert_equal('\033[1;32mHello\033[0m', utils.message('Hello'))
    else:
        assert_equal('*** MESSAGE ***: Hello', utils.message('Hello'))
Example #9
0
def main(args=None):
    """Entry point for nuc_data_make utility."""
    print(message(pyne_logo))

    make_funcs = [('atomic_mass', make_atomic_mass),
                  ('scattering_lengths', make_scattering_lengths),
                  ('decay', make_decay), ('simple_xs', make_simple_xs),
                  ('cinder', make_cinder),
                  ('materials', make_materials_library),
                  ('q_values', make_q_value),
                  ('dose_factors', make_dose_factors), ('eaf', make_eaf),
                  ('wimsd_fpy', wimsdfpy.make_fpy),
                  ('nds_fpy', ndsfpy.make_fpy)]
    make_map = dict(make_funcs)
    make_open = set([
        'atomic_mass', 'scattering_lengths', 'simple_xs', 'materials',
        'wimsd_fpy', 'nds_fpy', 'q_values', 'dose_factors'
    ])

    # Parse the command line arguments
    parser = argparse.ArgumentParser(
        description='Make a nuclear data library.')
    parser.add_argument('-o',
                        dest='nuc_data',
                        action='store',
                        default=nuc_data,
                        help='path to the output database file.')
    parser.add_argument('-b',
                        dest='build_dir',
                        action='store',
                        default=build_dir,
                        help='path to the build directory.')
    parser.add_argument('--datapath',
                        dest='datapath',
                        action='store',
                        default="",
                        help='MCNP DATAPATH.')
    parser.add_argument('--fetch-prebuilt',
                        dest='fetch_prebuilt',
                        action='store',
                        type=lambda s: 't' in s.lower() or 'y' in s.lower(),
                        default=True,
                        help='grab partially assembled file [y/n].')
    parser.add_argument('--make-open-only',
                        dest='make_open_only',
                        action='store',
                        type=lambda s: 't' in s.lower() or 'y' in s.lower(),
                        default=False,
                        help='only add open data to file [y/n].')
    parser.add_argument('-m',
                        dest='make',
                        action='store',
                        default='all',
                        help='comma-separated parts of nuc_data to make: ' +
                        ", ".join([mf[0]
                                   for mf in make_funcs]) + ', all, and none.')
    parser.add_argument('--check',
                        dest='hash_check',
                        action='store_true',
                        help='check hashes against built-in ones')
    parser.add_argument('--clean',
                        dest='clean',
                        type=int,
                        default=0,
                        help="""level to clean up existing files.
				 0: no cleaning (default).
				 1: clean nuc_data.
				 2: clean nuc_data and build_dir.""")
    args = parser.parse_args(args=args)

    # clean nuc data
    if args.clean in [1, 2]:
        print("Removing nuc_data from {0}".format(args.nuc_data))
        try:
            os.remove(args.nuc_data)
        except OSError:
            pass

    # Make the build dir
    if args.clean == 2 and os.path.exists(args.build_dir):
        print("Removing build_dir from {0}".format(args.build_dir))
        remove_tree(args.build_dir)
    mkpath(args.build_dir)

    # Determine what to make
    if args.make == 'none':
        make_order = []
    elif args.make == 'all':
        make_order = [mf[0] for mf in make_funcs]
    else:
        make_order = args.make.replace(' ', "").split(',')

    if args.make_open_only:
        make_order = [mo for mo in make_order if mo in make_open]

    # fetch prebuilt data library if possible
    if args.fetch_prebuilt:
        _fetch_prebuilt(args)

    # Make the various tables
    print("Making nuc_data at {0}".format(args.nuc_data))
    for mo in make_order:
        make_map[mo](args)

    if args.hash_check:
        print("Checking hashes")
        result = check_hashes(args.nuc_data)
        print("Results:")
        badsum = False
        for name, value in result:
            if value:
                print(" node " + name + " checksum matches")
            else:
                badsum = True
                print(" node " + name + " checksum doesn't match!!")
        if badsum is True:
            print(
                """You may need to try building the data from scratch using:\n
                  nuc_data_make --fetch-prebuilt False
                  """)
Example #10
0
def test_message():
    if os.name is 'posix':
        assert_equal('\033[1;32mHello\033[0m', utils.message('Hello'))
    else:
        assert_equal('*** MESSAGE ***: Hello', utils.message('Hello'))
Example #11
0
def main(args=None):
    """Entry point for nuc_data_make utility."""
    print(message(pyne_logo))

    make_funcs = [
        ("atomic_mass", make_atomic_mass),
        ("scattering_lengths", make_scattering_lengths),
        ("decay", make_decay),
        ("simple_xs", make_simple_xs),
        ("cinder", make_cinder),
        ("materials", make_materials_library),
        ("q_values", make_q_value),
        ("dose_factors", make_dose_factors),
        ("eaf", make_eaf),
        ("wimsd_fpy", wimsdfpy.make_fpy),
        ("nds_fpy", ndsfpy.make_fpy),
    ]
    make_map = dict(make_funcs)
    make_open = set(
        [
            "atomic_mass",
            "scattering_lengths",
            "simple_xs",
            "materials",
            "wimsd_fpy",
            "nds_fpy",
            "q_values",
            "dose_factors",
        ]
    )

    # Parse the command line arguments
    parser = argparse.ArgumentParser(description="Make a nuclear data library.")
    parser.add_argument(
        "-o",
        dest="nuc_data",
        action="store",
        default=nuc_data,
        help="path to the output database file.",
    )
    parser.add_argument(
        "-b",
        dest="build_dir",
        action="store",
        default=build_dir,
        help="path to the build directory.",
    )
    parser.add_argument(
        "--datapath", dest="datapath", action="store", default="", help="MCNP DATAPATH."
    )
    parser.add_argument(
        "--fetch-prebuilt",
        dest="fetch_prebuilt",
        action="store",
        type=lambda s: "t" in s.lower() or "y" in s.lower(),
        default=True,
        help="grab partially assembled file [y/n].",
    )
    parser.add_argument(
        "--make-open-only",
        dest="make_open_only",
        action="store",
        type=lambda s: "t" in s.lower() or "y" in s.lower(),
        default=False,
        help="only add open data to file [y/n].",
    )
    parser.add_argument(
        "-m",
        dest="make",
        action="store",
        default="all",
        help="comma-separated parts of nuc_data to make: "
        + ", ".join([mf[0] for mf in make_funcs])
        + ", all, and none.",
    )
    parser.add_argument(
        "--check",
        dest="hash_check",
        action="store_true",
        help="check hashes against built-in ones",
    )
    parser.add_argument(
        "--clean",
        dest="clean",
        type=int,
        default=0,
        help="""level to clean up existing files.
				 0: no cleaning (default).
				 1: clean nuc_data.
				 2: clean nuc_data and build_dir.""",
    )
    args = parser.parse_args(args=args)

    # clean nuc data
    if args.clean in [1, 2]:
        print("Removing nuc_data from {0}".format(args.nuc_data))
        try:
            os.remove(args.nuc_data)
        except OSError:
            pass

    # Make the build dir
    if args.clean == 2 and os.path.exists(args.build_dir):
        print("Removing build_dir from {0}".format(args.build_dir))
        remove_tree(args.build_dir)
    mkpath(args.build_dir)

    # Determine what to make
    if args.make == "none":
        make_order = []
    elif args.make == "all":
        make_order = [mf[0] for mf in make_funcs]
    else:
        make_order = args.make.replace(" ", "").split(",")

    if args.make_open_only:
        make_order = [mo for mo in make_order if mo in make_open]

    # fetch prebuilt data library if possible
    if args.fetch_prebuilt:
        _fetch_prebuilt(args)

    # Make the various tables
    print("Making nuc_data at {0}".format(args.nuc_data))
    for mo in make_order:
        make_map[mo](args)

    if args.hash_check:
        print("Checking hashes")
        result = check_hashes(args.nuc_data)
        print("Results:")
        badsum = False
        for name, value in result:
            if value:
                print(" node " + name + " checksum matches")
            else:
                badsum = True
                print(" node " + name + " checksum doesn't match!!")
        if badsum is True:
            print(
                """You may need to try building the data from scratch using:\n
                  nuc_data_make --fetch-prebuilt False
                  """
            )
Example #12
0
def main():
    """Entry point for nuc_data_make utility."""
    print message(pyne_logo)

    make_funcs = [('atomic_weight', make_atomic_weight),
                  ('scattering_lengths', make_scattering_lengths),
                  ('decay', make_decay), 
                  ('simple_xs', make_simple_xs), 
                  ('cinder', make_cinder), 
				  ('materials', make_materials_library),
                  ('eaf', make_eaf),
                  ]
    make_map = dict(make_funcs)
    make_open = set(['atomic_weight', 'scattering_lengths', 'simple_xs', 'materials'])

    # Parse the command line arguments
    parser = argparse.ArgumentParser(description='Make a nuclear data library.')
    parser.add_argument('-o', dest='nuc_data', action='store', default=nuc_data,
                        help='path to the output database file.')
    parser.add_argument('-b', dest='build_dir', action='store', default=build_dir,
                        help='path to the build directory.')
    parser.add_argument('--datapath', dest='datapath', action='store', default="",
                        help='MCNP DATAPATH.')
    parser.add_argument('--fetch-prebuilt', dest='fetch_prebuilt', action='store', 
                        type=lambda s: 't' in s.lower() or 'y' in s.lower(), 
                        default=True, help='grab partially assembled file [y/n].')
    parser.add_argument('--make-open-only', dest='make_open_only', action='store', 
                        type=lambda s: 't' in s.lower() or 'y' in s.lower(), 
                        default=False, help='only add open data to file [y/n].')
    parser.add_argument('-m', dest='make', action='store', default='all',
                        help='comma-separated parts of nuc_data to make: ' + \
                        ", ".join([mf[0] for mf in make_funcs]) + ', all, and none.')
    parser.add_argument('--clean', dest='clean', type=int, default=0,
                        help="""level to clean up existing files.
                                0: no cleaning (default).
                                1: clean nuc_data.
                                2: clean nuc_data and build_dir.""")
    args = parser.parse_args()

    # clean nuc data
    if args.clean in [1, 2]:
        print "Removing nuc_data from {0}".format(args.nuc_data)
        try:
            os.remove(args.nuc_data)
        except OSError:
            pass

    # Make the build dir
    if args.clean == 2:
        print "Removing build_dir from {0}".format(args.build_dir)
        remove_tree(args.build_dir)
    mkpath(args.build_dir)

    # Determine what to make
    if args.make == 'none':
        make_order = []
    elif args.make == 'all':
        make_order = [mf[0] for mf in make_funcs]
    else:   
        make_order = args.make.replace(' ', "").split(',')

    if args.make_open_only:
        make_order = [mo for mo in make_order if mo in make_open]

    # fetch prebuilt data library if possible
    if args.fetch_prebuilt:
        _fetch_prebuilt(args)

    # Make the various tables
    print "Making nuc_data at {0}".format(args.nuc_data)
    for mo in make_order:
        make_map[mo](args)
Example #13
0
def main(args=None):
    """Entry point for nuc_data_make utility."""
    print(message(pyne_logo))

    make_funcs = [('atomic_mass', make_atomic_mass),
                  ('scattering_lengths', make_scattering_lengths),
                  ('decay', make_decay),
                  ('simple_xs', make_simple_xs),
                  ('cinder', make_cinder),
                  ('materials', make_materials_library),
                  ('q_values', make_q_value),
                  ('dose_factors', make_dose_factors),
                  ('eaf', make_eaf),
                  ('wimsd_fpy', wimsdfpy.make_fpy),
                  ('nds_fpy', ndsfpy.make_fpy)
                  ]
    make_map = dict(make_funcs)
    make_open = set(['atomic_mass', 'scattering_lengths', 'simple_xs', 'materials',
                     'wimsd_fpy', 'nds_fpy', 'q_values', 'dose_factors'])

    # Parse the command line arguments
    parser = argparse.ArgumentParser(description='Make a nuclear data library.')
    parser.add_argument('-o', dest='nuc_data', action='store', default=nuc_data,
                        help='path to the output database file.')
    parser.add_argument('-b', dest='build_dir', action='store', default=build_dir,
                        help='path to the build directory.')
    parser.add_argument('--datapath', dest='datapath', action='store', default="",
                        help='MCNP DATAPATH.')
    parser.add_argument('--fetch-prebuilt', dest='fetch_prebuilt', action='store',
                        type=lambda s: 't' in s.lower() or 'y' in s.lower(),
                        default=True, help='grab partially assembled file [y/n].')
    parser.add_argument('--make-open-only', dest='make_open_only', action='store',
                        type=lambda s: 't' in s.lower() or 'y' in s.lower(),
                        default=False, help='only add open data to file [y/n].')
    parser.add_argument('-m', dest='make', action='store', default='all',
                        help='comma-separated parts of nuc_data to make: ' +
                        ", ".join([mf[0] for mf in make_funcs]) + ', all, and none.')
    parser.add_argument('--check', dest='hash_check', action='store_true',
                        help='check hashes against built-in ones')
    parser.add_argument('--clean', dest='clean', type=int, default=0,
                        help="""level to clean up existing files.
				 0: no cleaning (default).
				 1: clean nuc_data.
				 2: clean nuc_data and build_dir.""")
    args = parser.parse_args(args=args)

    # clean nuc data
    if args.clean in [1, 2]:
        print("Removing nuc_data from {0}".format(args.nuc_data))
        try:
            os.remove(args.nuc_data)
        except OSError:
            pass

    # Make the build dir
    if args.clean == 2 and os.path.exists(args.build_dir):
        print("Removing build_dir from {0}".format(args.build_dir))
        remove_tree(args.build_dir)
    mkpath(args.build_dir)

    # Determine what to make
    if args.make == 'none':
        make_order = []
    elif args.make == 'all':
        make_order = [mf[0] for mf in make_funcs]
    else:
        make_order = args.make.replace(' ', "").split(',')

    if args.make_open_only:
        make_order = [mo for mo in make_order if mo in make_open]

    # fetch prebuilt data library if possible
    if args.fetch_prebuilt:
        _fetch_prebuilt(args)

    # Make the various tables
    print("Making nuc_data at {0}".format(args.nuc_data))
    for mo in make_order:
        make_map[mo](args)

    if args.hash_check:
        print("Checking hashes")
        result = check_hashes(args.nuc_data)
        print("Results:")
        badsum = False
        for name, value in result:
            if value:
                print(" node " + name + " checksum matches")
            else:
                badsum = True
                print(" node " + name + " checksum doesn't match!!")
        if badsum is True:
            print("""You may need to try building the data from scratch using:\n
                  nuc_data_make --fetch-prebuilt False
                  """)
Example #14
0
def test_message():
    if os.name is "posix":
        assert_equal("\033[1;32mHello\033[0m", utils.message("Hello"))
    else:
        assert_equal("*** MESSAGE ***: Hello", utils.message("Hello"))