Exemple #1
0
def diffraction_pattern_calculation(params):

    number_channels, min_dist_fr_sample_center = params
    create_collimator_geometry(coll_length=min_dist_fr_sample_center,
                               number_channels=int(number_channels),
                               channel_length=min_dist_fr_sample_center,
                               detector_angles=[-45, -135],
                               outputfile=outputfile)
    simdir = os.path.join(
        parentpath, "out/optimization-NC_%s-dist_%s" %
        (number_channels, min_dist_fr_sample_center))
    run_script.run_mpi(instr,
                       simdir,
                       beam=scattered,
                       ncount=ncount,
                       nodes=nodes,
                       sample=sample,
                       sourceTosample=sourceTosample,
                       detector_size=detector_size,
                       overwrite_datafiles=True)

    dcs, I_d, error = reduction.reduce_all(simdir,
                                           conf,
                                           l1=14.699,
                                           l2=0.3,
                                           l3=0.5,
                                           bins=np.arange(0, 4, 0.01))
    return (dcs, I_d, error)
Exemple #2
0
def test_run_mpi():
    run_script.run_mpi(script,
                       workdir=workdir,
                       ncount=ncount,
                       buffer_size=int(5e5),
                       nodes=nodes,
                       use_gpu=False,
                       overwrite_datafiles=True)
    return
Exemple #3
0
def test_run_collimator():

    run_script.run_mpi(instr,
                       output,
                       beam=scattered,
                       ncount=ncount,
                       nodes=nodes,
                       angleMon1=-50.,
                       angleMon2=105.,
                       sample=sample,
                       sourceTosample_x=sourceTosample,
                       sourceTosample_y=sourceTosample,
                       sourceTosample_z=sourceTosample,
                       detector_size=detector_size,
                       overwrite_datafiles=True)
Exemple #4
0
def run(instrument_script,
        ncount,
        niters,
        mpi=False,
        nodes=1,
        acc_run=False,
        skip_ncounts=[],
        **kwds):
    outdir = 'out.debug-check-speed'
    if os.path.exists(outdir):
        shutil.rmtree(outdir)

    # TODO: this stdout file gets overwritten on each call, move or use append?
    stdout = open("./check-speed-stdout.txt", "w")
    sys.stderr = stdout

    avg_times = []
    for n in ncount:
        if n in skip_ncounts:
            # insert element to preserve ordering
            avg_times.append(np.nan)
            continue

        print(" Running '{}' with n={}".format(instrument_script, n))

        times = []
        # redirect script output to reduce terminal clutter
        for iter in range(niters + 1):
            sys.stdout = stdout
            buffer_size = int(n) if n > 1e6 else int(1e6)
            if buffer_size > 1e9:
                buffer_size = int(1e9)

            # get the runtime for the script. Note: this probably isn't the
            # best timing, since it will include the overhead of launching the
            # script and any file IO done inside the script, but there is no
            # current way to time individual components.
            # TODO: the stdout could be parsed to pull the process timings for acc components
            # TODO: there is still mcvine component output, likely from a subprocess in which this redirection has no effect
            if mpi:
                # run script in MPI mode
                # NOTE: with mcvine=0.44, pyyaml 5.3 must be used to avoid yaml load error. This is fixed in newer versions of mcvine.
                time_before = time.time_ns()
                run_script.run_mpi(instrument_script,
                                   outdir,
                                   nodes=nodes,
                                   buffer_size=buffer_size,
                                   ncount=n,
                                   overwrite_datafiles=True,
                                   **kwds)
                time_after = time.time_ns()
            elif acc_run:
                # use accelerated run script
                time_before = time.time_ns()
                run_acc_script.run(instrument_script,
                                   outdir,
                                   buffer_size=buffer_size,
                                   ncount=n,
                                   overwrite_datafiles=True,
                                   **kwds)
                time_after = time.time_ns()
            else:
                # use default run script (mcvine, single node)
                time_before = time.time_ns()
                run_script.run1(instrument_script,
                                outdir,
                                buffer_size=buffer_size,
                                ncount=n,
                                overwrite_datafiles=True,
                                **kwds)
                time_after = time.time_ns()

            # skip first run
            if iter < 1:
                continue

            delta = time_after - time_before
            times.append(delta)

        sys.stdout = sys.__stdout__

        time_avg = np.sum(np.asarray(times)) / len(times)
        avg_times.append(time_avg)
        print(" TIME = {} ms ({} s)".format(time_avg * 1e-6, time_avg * 1e-9))

    sys.stdout = sys.__stdout__
    sys.stderr = sys.__stderr__
    stdout.close()

    return avg_times
#!/usr/bin/env python

from mcvine import run_script
run_script.run_mpi('./sss.py',
                   'out',
                   ncount=8e6,
                   nodes=8,
                   overwrite_datafiles=True)
    def diffraction_pattern_calculation(self, params=[20, 20]):

        max_coll_len, chann_size = params

        if self.coll_sim:

            create_collimator_geometry(channel_size=chann_size,
                                       max_coll_len=max_coll_len,
                                       Snap_angle=self.Snap_angle,
                                       detector_angles=[-45])

            name = "length_%s-dist_%s" % (max_coll_len, chann_size)

        else:
            name = self.sampleassembly_fileName

        simdir = os.path.join(parent_dir, "out/%s" % (name))

        instr = os.path.join(libpath, 'myinstrument.py')

        # scattered_neutrons ='clampcellSi_scattered-neutrons_1e9_det-50_105_new'

        # scatterer = {(sampleassembly_fileName, 'shapeColl', 'coll_geometry', 'H', 'xyz'),
        #              }
        #
        # sa.makeSAXML(sampleassembly_fileName, scatterer)

        # sample= 'collimator_plastic'
        run_script.run_mpi(instr,
                           simdir,
                           beam=self.source_neutrons(),
                           ncount=self.ncount,
                           nodes=20,
                           angleMon1=-50.,
                           angleMon2=105.,
                           sample=self.sampleassembly_fileName,
                           sourceTosample_x=self.sourceTosample_x,
                           sourceTosample_y=self.sourceTosample_y,
                           sourceTosample_z=self.sourceTosample_z,
                           detector_size=0.45,
                           overwrite_datafiles=True)

        template = os.path.join(mantid_path, 'template.nxs')

        nexus_file_path = os.path.join(mantid_path, '{}.nxs'.format(name))

        det2nxs.create_nexus(simdir, nexus_file_path, template)

        SNAP_definition_file = os.path.join(mantid_path,
                                            'SNAP_virtual_Definition.xml')

        nexus_file_correctDet_path = os.path.join(
            mantid_path, '{}_correctDet.nxs'.format(name))

        rot.detector_position_for_reduction(nexus_file_path, conf,
                                            SNAP_definition_file,
                                            nexus_file_correctDet_path)

        if self.masking:
            masked_file_path = os.path.join(mantid_path,
                                            '{}_masked.nxs'.format(name))

            masked_template_path = os.path.join(
                mantid_path, '{}'.format(self.masked_template))

            mask.masking(nexus_file_correctDet_path, masked_template_path,
                         masked_file_path)

        else:
            masked_file_path = nexus_file_correctDet_path

        binning = [0.5, 0.01, 4.]
        d_sim, I_sim, error = red.mantid_reduction(masked_file_path, binning)

        plt.figure()
        plt.errorbar(d_sim, I_sim, error)
        plt.xlabel('d_spacing ()')
        plt.show()

        np.save(
            os.path.join(result_path, 'I_d_{sample}.npy'.format(sample=name)),
            [d_sim, I_sim, error])

        return (d_sim, I_sim, error)
Exemple #7
0
    def diffraction_pattern_calculation(self, params=[501.9, 444.5]):

        channel_len, coll_front_end_from_center = params

        if self.coll_sim:

            create_collimator_geometry(
                coll_front_end_from_center=coll_front_end_from_center,
                chanel_length=channel_len,
                Snap_angle=self.Snap_angle,
                detector_angles=[150])  #150

            name = "length_%s-dist_%s" % (channel_len,
                                          coll_front_end_from_center)

        else:
            name = self.sampleassembly_fileName

        simdir = os.path.join(parent_dir, "out/%s" % (name))

        # instr = os.path.join(libpath, 'myinstrument_multipleDet.py')

        instr = os.path.join(libpath, 'myinstrument.py')

        # scattered_neutrons ='clampcellSi_scattered-neutrons_1e9_det-50_105_new'

        # scatterer = {(sampleassembly_fileName, 'shapeColl', 'coll_geometry', 'H', 'xyz'),
        #              }
        #
        # sa.makeSAXML(sampleassembly_fileName, scatterer)

        # sample= 'collimator_plastic'
        import shutil
        if os.path.exists(simdir):
            shutil.rmtree(simdir)
        # run_script.run_mpi(instr, simdir,
        #                    beam=self.source_neutrons(), ncount=self.ncount,
        #                    nodes=20, angleMons=self.angleMons,
        #                    sample=self.sampleassembly_fileName,
        #                    sourceTosample_x=self.sourceTosample_x, sourceTosample_y=self.sourceTosample_y,
        #                    sourceTosample_z=self.sourceTosample_z, sampleTodetector_z=self.sampleTodetector_z,
        #                    detector_width=self.detector_width, detector_height=self.detector_height,
        #                    number_pixels_in_height=self.number_pixels_in_height,
        #                    number_of_box_in_height=self.number_of_box_in_height,
        #                    number_pixels_in_width=self.number_pixels_in_width,
        #                    number_of_box_in_width= self.number_of_box_in_width,
        #                    number_detectors=self.number_of_detectors,
        #                    overwrite_datafiles=True)

        run_script.run_mpi(
            instr,
            simdir,
            beam=self.source_neutrons(),
            ncount=self.ncount,
            nodes=20,
            angleMon1=150,
            sample=self.sampleassembly_fileName,
            sourceTosample_x=self.sourceTosample_x,
            sourceTosample_y=self.sourceTosample_y,
            sourceTosample_z=self.sourceTosample_z,
            sampleTodetector_z=self.sampleTodetector_z,
            detector_width=self.detector_width,
            detector_height=self.detector_height,
            number_pixels_in_height=self.number_pixels_in_height,
            number_of_box_in_height=self.number_of_box_in_height,
            number_pixels_in_width=self.number_pixels_in_width,
            number_of_box_in_width=self.number_of_box_in_width,
            multiple_detectors=False,
            overwrite_datafiles=True)

        SNAP_definition_file = os.path.join(mantid_path,
                                            'SNAPOneDet_virtual_definition.xml'
                                            )  # Vulcan_virtual_Definition.xml

        template = os.path.join(
            mantid_path, 'template_snapOneDet.nxs')  # vulcan_template.nxs

        nxs_template.create(SNAP_definition_file,
                            ntotpixels=self.number_of_total_DetectorPixels,
                            outpath=template,
                            pulse_time_end=1e5)

        nexus_file_path = os.path.join(mantid_path, '{}.nxs'.format(name))

        det2nxs.create_nexus(simdir,
                             nexus_file_path,
                             template,
                             N=self.number_of_total_DetectorPixels)

        nexus_file_correctDet_path = os.path.join(
            mantid_path, '{}_correctDet.nxs'.format(name))

        conf = Conf(self.moderatorTosample_z, self.angleMons,
                    self.sampleTodetector_z)
        rot.detector_position_for_reduction(nexus_file_path, conf,
                                            SNAP_definition_file,
                                            nexus_file_correctDet_path)

        if self.masking:
            masked_file_path = os.path.join(mantid_path,
                                            '{}_masked.nxs'.format(name))

            masked_template_path = os.path.join(
                mantid_path, '{}'.format(self.masked_template))

            mask.masking(nexus_file_correctDet_path, masked_template_path,
                         masked_file_path)

        else:
            masked_file_path = nexus_file_correctDet_path

        binning = [0.5, 0.01, 4.]
        d_sim, I_sim, error = red.mantid_reduction(masked_file_path, binning)

        plt.figure()
        plt.errorbar(d_sim, I_sim, error)
        plt.xlabel('d_spacing ()')
        plt.show()

        np.save(
            os.path.join(result_path, 'I_d_{sample}.npy'.format(sample=name)),
            [d_sim, I_sim, error])

        return (d_sim, I_sim, error)
Exemple #8
0
#!/usr/bin/env python

from mcvine import run_script
run_script.run_mpi('./ARCS_10_25_2008_mcvine_revised.py',
                   'out',
                   ncount=8e7,
                   nodes=8,
                   overwrite_datafiles=True)