Exemplo n.º 1
0
    def process_property(physical_property, **_):
        """Return a result as if the property had been successfully estimated."""
        return_object = CalculationLayerResult()
        return_object.physical_property = physical_property
        return_object.calculated_property = physical_property

        return return_object
Exemplo n.º 2
0
    def process_successful_property(physical_property, layer_directory, **_):
        """Return a result as if the property had been successfully estimated."""

        dummy_data_directory = path.join(layer_directory, "good_dummy_data")
        makedirs(dummy_data_directory, exist_ok=True)

        dummy_stored_object = StoredSimulationData()
        dummy_stored_object.substance = physical_property.substance
        dummy_stored_object.thermodynamic_state = physical_property.thermodynamic_state
        dummy_stored_object.property_phase = physical_property.phase
        dummy_stored_object.force_field_id = ""
        dummy_stored_object.coordinate_file_name = ""
        dummy_stored_object.trajectory_file_name = ""
        dummy_stored_object.statistics_file_name = ""
        dummy_stored_object.statistical_inefficiency = 1.0
        dummy_stored_object.number_of_molecules = 10
        dummy_stored_object.source_calculation_id = ""

        dummy_stored_object_path = path.join(layer_directory,
                                             "good_dummy_data.json")

        with open(dummy_stored_object_path, "w") as file:
            json.dump(dummy_stored_object, file, cls=TypedJSONEncoder)

        return_object = CalculationLayerResult()
        return_object.physical_property = physical_property
        return_object.data_to_store = [(dummy_stored_object_path,
                                        dummy_data_directory)]

        return return_object
Exemplo n.º 3
0
    def process_failed_property(physical_property, **_):
        """Return a result as if the property could not be estimated."""

        return_object = CalculationLayerResult()
        return_object.physical_property = physical_property
        return_object.exceptions = [
            EvaluatorException(message="Failure Message")
        ]

        return return_object
Exemplo n.º 4
0
    def workflow_to_layer_result(queued_properties, provenance,
                                 workflow_results, **_):
        """Converts a list of `WorkflowResult` to a list of `CalculationLayerResult`
        objects.

        Parameters
        ----------
        queued_properties: list of PhysicalProperty
            The properties being estimated by this layer
        provenance: dict of str and str
            The provenance of each property.
        workflow_results: list of WorkflowResult
            The results of each workflow.

        Returns
        -------
        list of CalculationLayerResult
            The calculation layer result objects.
        """
        properties_by_id = {x.id: x for x in queued_properties}
        results = []

        for workflow_result in workflow_results:

            calculation_result = CalculationLayerResult()
            calculation_result.exceptions.extend(workflow_result.exceptions)

            results.append(calculation_result)

            if len(calculation_result.exceptions) > 0:
                continue

            physical_property = properties_by_id[workflow_result.workflow_id]
            physical_property = copy.deepcopy(physical_property)
            physical_property.source = provenance[physical_property.id]
            physical_property.value = workflow_result.value.value
            physical_property.uncertainty = workflow_result.value.error

            if len(workflow_result.gradients) > 0:
                physical_property.gradients = workflow_result.gradients

            calculation_result.physical_property = physical_property
            calculation_result.data_to_store.extend(
                workflow_result.data_to_store)

        return results
Exemplo n.º 5
0
def test_serialize_layer_result():
    """Tests that the `CalculationLayerResult` can be properly
    serialized and deserialized."""

    dummy_result = CalculationLayerResult()

    dummy_result.physical_property = create_dummy_property(Density)
    dummy_result.exceptions = [EvaluatorException()]

    dummy_result.data_to_store = [("dummy_object_path", "dummy_directory")]

    dummy_result_json = json.dumps(dummy_result, cls=TypedJSONEncoder)

    recreated_result = json.loads(dummy_result_json, cls=TypedJSONDecoder)
    recreated_result_json = json.dumps(recreated_result, cls=TypedJSONEncoder)

    assert recreated_result_json == dummy_result_json
Exemplo n.º 6
0
    def return_bad_result(physical_property, layer_directory, **_):
        """Return a result which leads to an unhandled exception."""

        dummy_data_directory = path.join(layer_directory, "bad_dummy_data")
        makedirs(dummy_data_directory, exist_ok=True)

        dummy_stored_object = StoredSimulationData()
        dummy_stored_object_path = path.join(layer_directory,
                                             "bad_dummy_data.json")

        with open(dummy_stored_object_path, "w") as file:
            json.dump(dummy_stored_object, file, cls=TypedJSONEncoder)

        return_object = CalculationLayerResult()
        return_object.physical_property = physical_property
        return_object.data_to_store = [(dummy_stored_object_path,
                                        dummy_data_directory)]

        return return_object