Beispiel #1
0
 def test_disable_caching(self):
     """Test the `disable_caching` context manager with specific identifier."""
     with disable_caching(identifier='aiida.calculations:arithmetic.add'):
         self.assertFalse(
             get_use_cache(identifier='aiida.calculations:arithmetic.add'))
     self.assertTrue(
         get_use_cache(identifier='aiida.calculations:arithmetic.add'))
Beispiel #2
0
def test_disable_caching_specific(configure_caching):
    """
    Check that using disable_caching for a specific identifier works.
    """
    identifier = 'some_ident'
    with configure_caching({'default': True}):
        with disable_caching(identifier=identifier):
            assert not get_use_cache(identifier=identifier)
Beispiel #3
0
 def test_contextmanager_disable_global(self):
     """Test the `disable_caching` context manager without specific identifier."""
     with disable_caching():
         self.assertTrue(
             get_use_cache(identifier='aiida.calculations:arithmetic.add')
         )  # explicitly set, hence not overwritten
         self.assertFalse(
             get_use_cache(
                 identifier='aiida.calculations:templatereplacer'))
Beispiel #4
0
def test_disable_caching_global(configure_caching):
    """
    Check that using disable_caching for a specific identifier works.
    """
    specific_identifier = 'some_ident'
    with configure_caching(config_dict={'default': True, 'enabled': [specific_identifier]}):
        with disable_caching():
            assert not get_use_cache(identifier='some_other_ident')
            assert not get_use_cache(identifier=specific_identifier)
Beispiel #5
0
def test_enable_disable_invalid(identifier):
    """
    Test that the enable and disable context managers raise when given
    an invalid identifier.
    """
    with pytest.raises(ValueError):
        with enable_caching(identifier=identifier):
            pass
    with pytest.raises(ValueError):
        with disable_caching(identifier=identifier):
            pass
Beispiel #6
0
    def submit_scf_calculation(self):
        """Create and submit an SCF calculation."""
        if "test_run" in self.inputs and self.inputs.test_run.value:
            self.report(
                "`test_run` specified, stopping before submitting scf calculation"
            )
            return self.exit_codes.END_OF_TEST_RUN

        inputs = AttributeDict(self.exposed_inputs(self._scf_class, self._scf_name))
        inputs["metadata"]["call_link_label"] = "calc_{}".format(self._scf_name)
        try:
            with disable_caching():
                # even if the calculation has already been run, the remote folder may not be available
                future = self.submit(self._scf_class, **inputs)
        except Exception as err:
            self.report("SCF submission failed: {}".format(err))
            return self.exit_codes.ERROR_SCF_SUBMISSION_FAILED

        self.report("launched SCF calculation: {}".format(future))
        return ToContext(calc_scf=future)