Пример #1
0
    def test_parallel_sparse(self):
        """Tests creating sparse output parallelly.
        """
        # Test indices
        samples = [bulk("NaCl", "rocksalt", a=5.64), bulk('Cu', 'fcc', a=3.6)]
        desc = SineMatrix(n_atoms_max=5,
                          permutation="none",
                          flatten=True,
                          sparse=True)
        n_features = desc.get_number_of_features()

        # Multiple systems, serial job
        output = desc.create(
            system=samples,
            n_jobs=1,
        ).toarray()
        assumed = np.empty((2, n_features))
        assumed[0, :] = desc.create(samples[0]).toarray()
        assumed[1, :] = desc.create(samples[1]).toarray()
        self.assertTrue(np.allclose(output, assumed))

        # Multiple systems, parallel job
        output = desc.create(
            system=samples,
            n_jobs=2,
        ).toarray()
        assumed = np.empty((2, n_features))
        assumed[0, :] = desc.create(samples[0]).toarray()
        assumed[1, :] = desc.create(samples[1]).toarray()
        self.assertTrue(np.allclose(output, assumed))

        # Non-flattened output
        desc = SineMatrix(n_atoms_max=5,
                          permutation="none",
                          flatten=False,
                          sparse=True)
        output = [
            x.toarray() for x in desc.create(
                system=samples,
                n_jobs=2,
            )
        ]
        assumed = np.empty((2, 5, 5))
        assumed[0] = desc.create(samples[0]).toarray()
        assumed[1] = desc.create(samples[1]).toarray()
        self.assertTrue(np.allclose(np.array(output), assumed))
Пример #2
0
    def test_parallel_dense(self):
        """Tests creating dense output parallelly."""
        samples = [bulk("NaCl", "rocksalt", a=5.64), bulk("Cu", "fcc", a=3.6)]
        desc = SineMatrix(n_atoms_max=5,
                          permutation="none",
                          flatten=True,
                          sparse=False)
        n_features = desc.get_number_of_features()

        # Determining number of jobs based on the amount of CPUs
        desc.create(system=samples, n_jobs=-1, only_physical_cores=False)
        desc.create(system=samples, n_jobs=-1, only_physical_cores=True)

        # Multiple systems, serial job
        output = desc.create(
            system=samples,
            n_jobs=1,
        )
        assumed = np.empty((2, n_features))
        assumed[0, :] = desc.create(samples[0])
        assumed[1, :] = desc.create(samples[1])
        self.assertTrue(np.allclose(output, assumed))

        # Multiple systems, parallel job
        output = desc.create(
            system=samples,
            n_jobs=2,
        )
        assumed = np.empty((2, n_features))
        assumed[0, :] = desc.create(samples[0])
        assumed[1, :] = desc.create(samples[1])
        self.assertTrue(np.allclose(output, assumed))

        # Non-flattened output
        desc = SineMatrix(n_atoms_max=5,
                          permutation="none",
                          flatten=False,
                          sparse=False)
        output = desc.create(
            system=samples,
            n_jobs=2,
        )
        assumed = np.empty((2, 5, 5))
        assumed[0] = desc.create(samples[0])
        assumed[1] = desc.create(samples[1])
        self.assertTrue(np.allclose(np.array(output), assumed))
Пример #3
0
 def test_number_of_features(self):
     """Tests that the reported number of features is correct.
     """
     desc = SineMatrix(n_atoms_max=5, permutation="none", flatten=False)
     n_features = desc.get_number_of_features()
     self.assertEqual(n_features, 25)