当前位置: 首页>>代码示例>>Python>>正文


Python MPICommons.isMaster方法代码示例

本文整理汇总了Python中KMCLib.Backend.Backend.MPICommons.isMaster方法的典型用法代码示例。如果您正苦于以下问题:Python MPICommons.isMaster方法的具体用法?Python MPICommons.isMaster怎么用?Python MPICommons.isMaster使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KMCLib.Backend.Backend.MPICommons的用法示例。


在下文中一共展示了MPICommons.isMaster方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testConstruction

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def testConstruction(self):
        """ Test the LatticeTrajectory object can be constructed. """
        # Setup input.
        sites = [[1.0,1.0,2.3],
                 [3.4,4.5,4.3],
                 [3.7,7.5,6.5]]
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        trajectory_filename = os.path.join(name, "tmp_trajectory_file.py")

        if MPICommons.isMaster():
            self.__files_to_remove.append(trajectory_filename)

        # Construct with default values.
        dt = LatticeTrajectory(trajectory_filename, Config(sites))

        # Check the defaults.
        self.assertAlmostEqual( dt._Trajectory__max_buffer_time,  60*30 )
        self.assertEqual( dt._Trajectory__max_buffer_size, 1024*1024*10 )

        # Construct.
        t = LatticeTrajectory(trajectory_filename,
                              Config(sites),
                              max_buffer_time=100.0,
                              max_buffer_size=100000)

        # Check the stored values.
        self.assertEqual( t._Trajectory__max_buffer_time,  100.0 )
        self.assertEqual( t._Trajectory__max_buffer_size, 100000 )
        self.assertEqual( t._trajectory_filename, trajectory_filename )

        # Open the trajectory file and check that we can read the meta
        # information and sites.
        if MPICommons.isMaster():
            global_dict = {}
            local_dict  = {}
            execfile(trajectory_filename, global_dict, local_dict)

            # Get the version and creation time.
            read_version  = local_dict["version"]
            read_creation = local_dict["creation_time"]

            # Check that they are of corect type.
            self.assertTrue( isinstance(read_version, str) )
            self.assertTrue( isinstance(read_creation, str) )

            # Check the sites.
            read_sites = numpy.array(local_dict["sites"])
            ref_sites  = numpy.array(sites)
            self.assertAlmostEqual( numpy.linalg.norm(read_sites - ref_sites), 0.0, 10 )

            # Check the empty lists.
            read_times = local_dict["times"]
            read_steps = local_dict["steps"]
            read_types = local_dict["types"]
            empty_list = []
            self.assertEqual( read_times, empty_list )
            self.assertEqual( read_steps, empty_list )
            self.assertEqual( read_types, empty_list )
开发者ID:lmpizarro,项目名称:KMCLib,代码行数:62,代码来源:LatticeTrajectoryTest.py

示例2: testVersion

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def testVersion(self):
        """ Test the LatticeTrajectory file version number string. """
        # Setup input.
        sites = [[1.0,1.0,2.3],
                 [3.4,4.5,4.3],
                 [3.7,7.5,6.5]]
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        trajectory_filename = os.path.join(name, "tmp_trajectory_file.py")

        if MPICommons.isMaster():
            self.__files_to_remove.append(trajectory_filename)

        # Construct.
        t = LatticeTrajectory(trajectory_filename, Config(sites))

        # Open the trajectory file and check that we can read the meta
        # information and sites.
        if MPICommons.isMaster():
            global_dict = {}
            local_dict  = {}
            execfile(trajectory_filename, global_dict, local_dict)

            # Get the version and check.
            read_version  = local_dict["version"]
            ref_version = "2013.1.0"
            self.assertEqual( read_version, ref_version )
开发者ID:lmpizarro,项目名称:KMCLib,代码行数:30,代码来源:LatticeTrajectoryTest.py

示例3: testWriteHeader

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def testWriteHeader(self):
        """ Test the header output. """
        # Get a file name.
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        trajectory_filename = os.path.join(name, "tmp_trajectory.xyz")

        if MPICommons.isMaster():
            self.__files_to_remove.append(trajectory_filename)

        # Setup the trajectory object.
        unit_cell = KMCUnitCell(cell_vectors=[[1.0, 0.0, 0.0],
                                              [0.0, 1.0, 0.0],
                                              [0.0, 0.0, 1.0]],
                                basis_points=[[0.0, 0.0, 0.0]])
        lattice = KMCLattice(unit_cell=unit_cell,
                             periodic=(True, True, True),
                             repetitions=(4,2,3))

        config = KMCConfiguration(lattice=lattice,
                                 types=["A","B","C"]*8)

        t = XYZTrajectory(trajectory_filename=trajectory_filename,
                          configuration=config,
                          max_buffer_size=12345,
                          max_buffer_time=123.0)

        if MPICommons.isMaster():

            # Check that the header was written.
            self.assertTrue(os.path.exists(trajectory_filename))

            # Check the content of the header.
            with open(trajectory_filename, "r") as f:
                content = f.read()

            ref_content = """KMCLib XYZ FORMAT VERSION 2013.10.15

CELL VECTORS
a: 1.0000000000e+00 0.0000000000e+00 0.0000000000e+00
b: 0.0000000000e+00 1.0000000000e+00 0.0000000000e+00
c: 0.0000000000e+00 0.0000000000e+00 1.0000000000e+00

REPETITIONS 4 2 3

PERIODICITY True True True

"""
            self.assertEqual( content, ref_content )
开发者ID:PytLab,项目名称:KMCLib,代码行数:52,代码来源:XYZTrajectoryTest.py

示例4: printResults

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def printResults(self, stream=sys.stdout):
        """
        Print the results to the stream.

        :param stream: The stream to print to.
        """
        # Only master writes.
        if MPICommons.isMaster():
            stream.write("%15s %15s %15s %12s %12s\n"%("  time (t)", " count (n)", "(dn/dt)   ", "stdErr", "relErr"))
            n_tot  = 0
	    actualTot = 0
            t = 0.0
            for i,n in enumerate(self.__data):
                # Calculate the values to present.
                t  = i * self.__time_interval

		if t>=self.__transientTime:
                    actualTot += n

                dt = self.__time_interval
                n_tot += n
                dn     = n
                rateEst = dn/dt
                stdErr = math.sqrt(dn)/t
                # Only for times != zero.
                if i > 0:
                    stream.write("%15.5f %15i %15.5f %15.5f 15.5f\n"%(t, n_tot, rateEst, stdErr, 100.0*(stdErr/rateEst)))
            eqTime = t - self.__transientTime
            eqRate = actualTot/eqTime
            eqStdErr = math.sqrt(actualTot)/eqTime
            stream.write("\nThere were " + "%15i"%(actualTot) + " counts after equilibration. Therefore, the equilibrium rate estimate is " + "%15.5f"%(actualTot/eqTime) + "+/-" + "%15.5f"%(eqStdErr) + ".")
开发者ID:joshuahellier,项目名称:PhDStuff,代码行数:33,代码来源:PoissonStatistics.py

示例5: flush

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def flush(self):
        """ Write all buffers to file. """
        if not len(self.__step) < 1:

            # Make sure only master writes.
            if MPICommons.isMaster():

                # Write data to file.
                with open(self._trajectory_filename, 'a') as trajectory:
                    for i in range(len(self.__step)):

                        step = self.__step[i]
                        time = self.__time[i]
                        n_atoms = len(self.__atom_id_types[i])

                        trajectory.write("STEP %i\n"%(step))
                        trajectory.write("          %i\n"%(n_atoms))
                        trajectory.write("    TIME %15.10e\n"%(time))

                        for j in range(n_atoms):
                            t = self.__atom_id_types[i][j]
                            c = self.__atom_id_coordinates[i][j]
                            trajectory.write(" %16s   %15.10e %15.10e %15.10e  %i\n"%(t, c[0], c[1], c[2], j))

            # While the other processes wait.
            MPICommons.barrier()

            # Reset the buffers.
            self.__atom_id_types = []
            self.__atom_id_coordinates = []
            self.__time = []
            self.__step = []
开发者ID:PytLab,项目名称:KMCLib,代码行数:34,代码来源:XYZTrajectory.py

示例6: printResults

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def printResults(self, stream=sys.stdout):
        """
        Print the results to a stream.

        :param stream: The stream to print to. Defaults to 'sys.stdout'.
        """
        # Only master writes.
        if MPICommons.isMaster():

            # Bunch the results together and cutoff.
            cutoff_bin = self.safeCutoff()
            all_results = zip(self.__time_steps,
                              self.__results[0],
                              self.__results[1],
                              self.__results[2],
                              self.__results[3],
                              self.__results[4],
                              self.__results[5],
                              self.__results[6],
                              self.__std_dev[0],
                              self.__std_dev[1],
                              self.__std_dev[2],
                              self.__std_dev[3],
                              self.__std_dev[4],
                              self.__std_dev[5],
                              self.__std_dev[6],
                              self.__n_eff)[:cutoff_bin]
            stream.write("%11s %11s %11s %11s %11s %11s %11s %11s %11s %11s %11s %11s %11s %11s %11s %11s\n"%("TIME ", "MSD_x ", "DSD_y ", "MSD_z ", "MSD_xy ", "MSD_xz ", "MSD_yz ", "MSD_xyz ", "STD_x ", "STD_y ", "STD_z ", "STD_xy ", "STD_xz ", "STD_yz ", "STD_xyz ", "N_eff"))
            for t, x, y, z, xy, xz, yz, xyz, sx, sy, sz, sxy, sxz, syz, sxyz, nf in all_results:
                stream.write("%11.5e %11.5e %11.5e %11.5e %11.5e %11.5e %11.5e %11.5e %11.5e %11.5e %11.5e %11.5e %11.5e %11.5e %11.5e %11.5e\n"%(t, x, y, z, xy, xz, yz, xyz, sx, sy, sz, sxy, sxz, syz, sxyz, nf))
开发者ID:PytLab,项目名称:KMCLib,代码行数:32,代码来源:OnTheFlyMSD.py

示例7: printResults

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def printResults(self, stream=sys.stdout):
        """
        Print the results to the stream.

        :param stream: The stream to print to.
        """
        # Only master writes.
        if MPICommons.isMaster():
            stream.write("%15s %15s %15s %12s\n"%("  time (t)", " count (n)", "(dn/dt)   ", "stdErr"))
            n_tot  = 0
	    actualTot = 0
            t = 0.0
            for i,n in enumerate(self.__data):
                # Calculate the values to present.
                t  = i * self.__time_interval
                actualTot += n
                dt = self.__time_interval
                n_tot += n
                dn     = n
                rateEst = self.__floatAnalInterval*dn/dt
                stdErr = self.__floatAnalInterval*math.sqrt(dn)/dt
                # Only for times != zero.
                if (i > 0):
                    stream.write("%15.5f %15i"%(t, n_tot) +"        "+ "{:.6E}".format(rateEst) +"        "+"{:.3E}".format(stdErr) +"\n")
            eqTime = self.__finalTime - self.__initialTime
            stream.write("\nOverall we counted the following number of counts in the following amount of time: " + "%6i"%(actualTot) + " " + "{:.6E}".format(eqTime))
开发者ID:joshuahellier,项目名称:PhDStuff,代码行数:28,代码来源:ProcessStatistics.py

示例8: __writeHeader

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def __writeHeader(self, configuration):
        """
        Write the header to the file.

        :param configuration: The configuration of the system.
        """
        # Make sure only master writes.
        if MPICommons.isMaster():

            # Open the file and write the meta information.
            with open(self._trajectory_filename, 'w') as trajectory:

                # Version.
                trajectory.write("KMCLib XYZ FORMAT VERSION 2013.10.15\n\n")

                # Cellvectors.
                cell_vectors = configuration.lattice().unitCell().cellVectors()
                trajectory.write("CELL VECTORS\n")
                trajectory.write("a: %15.10e %15.10e %15.10e\n"%(cell_vectors[0][0], cell_vectors[0][1], cell_vectors[0][2]))
                trajectory.write("b: %15.10e %15.10e %15.10e\n"%(cell_vectors[1][0], cell_vectors[1][1], cell_vectors[1][2]))
                trajectory.write("c: %15.10e %15.10e %15.10e\n\n"%(cell_vectors[2][0], cell_vectors[2][1], cell_vectors[2][2]))

                # Repetitions.
                repetitions = configuration.lattice().repetitions()
                trajectory.write("REPETITIONS %i %i %i\n\n"%(repetitions[0], repetitions[1], repetitions[2]))

                # Periodicity.
                periodicity = configuration.lattice().periodic()
                trajectory.write("PERIODICITY %s %s %s\n\n"%(str(periodicity[0]), str(periodicity[1]), str(periodicity[2])))

        # While the other processes wait.
        MPICommons.barrier()
开发者ID:PytLab,项目名称:KMCLib,代码行数:34,代码来源:XYZTrajectory.py

示例9: testConstruction

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def testConstruction(self):
        """ Test that the XYZTrajectory object can be constructed. """
        filename = "abc123.xyz"
        name = os.path.abspath(os.path.dirname(__file__))
        name = os.path.join(name, "..", "..")
        name = os.path.join(name, "TestUtilities", "Scratch")
        filename = os.path.join(name, filename)

        if MPICommons.isMaster():
            self.__files_to_remove.append(filename)

        unit_cell = KMCUnitCell(cell_vectors=[[1.0, 0.0, 0.0],
                                              [0.0, 1.0, 0.0],
                                              [0.0, 0.0, 1.0]],
                                basis_points=[[0.0, 0.0, 0.0]])
        lattice = KMCLattice(unit_cell=unit_cell,
                             periodic=(True, True, True),
                             repetitions=(4,4,4))

        config = KMCConfiguration(lattice=lattice,
                                 types=["A","B","C","D"]*16)

        t = XYZTrajectory(trajectory_filename=filename,
                          configuration=config,
                          max_buffer_size=12345,
                          max_buffer_time=123.0)

        # Check that the internal memory buffers have been initiated.
        self.assertEqual(t._XYZTrajectory__atom_id_types, [])
        self.assertEqual(t._XYZTrajectory__atom_id_coordinates, [])
        self.assertEqual(t._XYZTrajectory__time, [])
        self.assertEqual(t._XYZTrajectory__step, [])
开发者ID:PytLab,项目名称:KMCLib,代码行数:34,代码来源:XYZTrajectoryTest.py

示例10: printResults

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def printResults(self, stream=sys.stdout):
        """
        Print the results to the stream.

        :param stream: The stream to print to.
        """
        # Only master writes.
        if MPICommons.isMaster():

            # The format string for the values.
            format_str = " %15.3e"*(len(self.__empty_count))
            format_str += "\n"

            # The format string for the counts.
            format_str_1 = " %15s"*(len(self.__empty_count))
            format_str_1 += "\n"

            types_str = ["time"]
            for t in self.__type_names[1:]:
                types_str.append(t)

            stream.write(format_str_1%tuple(types_str))

            for i,d in enumerate(self.__data):
                # Calculate the time.
                t  = i * self.__time_interval + (self.__time_interval / 2.0)

                # Append the values.
                tt = [t]
                for dd in d[1:]:
                    tt.append(dd)

                # Print.
                stream.write(format_str%tuple(tt))
开发者ID:PytLab,项目名称:KMCLib,代码行数:36,代码来源:Composition.py

示例11: tearDown

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
 def tearDown(self):
     """ The tearDown method for test fixtures. """
     # Make sure to stop simultaneously.
     MPICommons.barrier()
     for f in self.__files_to_remove:
         # Make sure only master delets files, while slaves wait.
         if MPICommons.isMaster():
             os.remove(f)
         MPICommons.barrier()
开发者ID:lulzzz,项目名称:KMCLib,代码行数:11,代码来源:TrajectoryTest.py

示例12: printResults

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def printResults(self, stream=sys.stdout):
        """
        Print the results to the stream.

        :param stream: The stream to print to.
        """
        # Only master writes.
        if MPICommons.isMaster():
            for item in self.__histogram:
                stream.write(str(item[0])+" "+str(item[1])+"\n")
开发者ID:joshuahellier,项目名称:PhDStuff,代码行数:12,代码来源:BlockStats.py

示例13: printResults

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def printResults(self, stream=sys.stdout):
        """
        Print the results to the stream.

        :param stream: The stream to print to.
        """
        # Only master writes.
        if MPICommons.isMaster():

            all_results = zip(self.__time_steps, self.__histogram, self.__normalized_histogram)
            for t, v, n in all_results:
                stream.write("%10.5f %10i %20.15f\n"%(t, v, n))
开发者ID:PytLab,项目名称:KMCLib,代码行数:14,代码来源:TimeStepDistribution.py

示例14: prettyPrint

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
def prettyPrint(msg, output=None):
    """
    Utility function for printing an output string to screen.

    :param msg: The message to print.
    :type msg: str

    :param out: The stream to write to. Defaults to sys.stdout.
    """
    # Set the default.
    if output is None:
        output = sys.stdout

    # Write.
    if MPICommons.isMaster():
        output.write(msg)
        output.write("\n")
    MPICommons.barrier()
开发者ID:supersonic594,项目名称:KMCLib,代码行数:20,代码来源:PrintUtilities.py

示例15: __writeToFile

# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import isMaster [as 别名]
    def __writeToFile(self, simulation_time_buffer, step_buffer, types_buffer):
        """
        Append the types and time information to the trajectory.
        The trajectory if flushed to file if the flush time limit has passed.

        :param simulation_time_buffer: A list of simulation times to be written to disk.
        :param step_buffer:            A list of step numbers to be written.
        :param types_buffer:           The types buffer given as a list of lists of strings.
        """
        # Save to file.

        # Make sure only master writes.
        if MPICommons.isMaster():
            with open(self.__trajectory_filename, 'a') as trajectory:
                for (sim_time, step, types) in zip(simulation_time_buffer, step_buffer, types_buffer):
                    trajectory.write( "times.append(%f)\n"%sim_time )
                    trajectory.write( "steps.append(%i)\n"%step )

                    # Write the types.
                    types_str = "types.append(["
                    indent = " "*14
                    row_length = len(types_str)
                    for t in types[:-1]:
                        row_length += len(t) + 2
                        types_str += "\"" + t + "\"" + ","

                        # Berak the row if above 70 positions.
                        if row_length >= 70:
                            types_str += "\n" + indent
                            row_length = len(indent)

                    # Add the last type.
                    types_str += "\"" + types[-1] + "\"" + "])\n"

                    # Write it to file.
                    trajectory.write(types_str)

        # While the others wait.
        MPICommons.barrier()

        # Update the time.
        self.__time_last_dump = time.time()
开发者ID:lulzzz,项目名称:KMCLib,代码行数:44,代码来源:Trajectory.py


注:本文中的KMCLib.Backend.Backend.MPICommons.isMaster方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。