CLOVER-energy / CLOVER

CLOVER minigrid simulation and optimisation for supporting rural electrification in developing countries
MIT License
18 stars 3 forks source link

Potential rounding error #104

Open BenWinchester opened 2 years ago

BenWinchester commented 2 years ago

Describe the bug

There is a potential rounding error in CLOVER which is leading to it producing incorrect results.

A case point for this can be found within the integration testing, specifically, a test involving diesel backup generation, pv panels, and storage. With the diesel backup threshold set to be 0.1, it is expected that the blackouts for the system over the course of the simulation should come out at 0.1. However, the value of 0.099 is reported. This may be an actual error within the calculations of CLOVER, or, more hopefully, it is a simple rounding error.

To Reproduce

Steps to reproduce the behavior:

  1. Run '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behaviour

A clear and concise description of what you expected to happen.

Screenshots

Code snippet

The specific lines, namely, that diesel is being modelled, and that blackouts are 0.099, have been highlighted.

    @pytest.mark.integrest
    def test_self_prioritise_diesel_pv_and_storage(self):
        """
        Tests the case with diesel, PV and storage.

        The test simulation uses:
            - a PV system size of 20 kWP;
            - a storage system size of 25 kWh.

        """

        info_file_data = self._run_clover_simulation(
+           True,
            False,
            True,
            True,
            prioritise_self_generation=False,
            pv_size=20,
            storage_size=25,
        )
        self._check_output(
            info_file_data,
            average_daily_diesel=5.548,
            average_daily_grid_energy=0.0,
            average_daily_grid_times=0.0,
            average_daily_renewables_energy=4.271,
            average_daily_storage_energy=9.807,
+           blackouts=0.099,
            cumulative_cost=33821.539,
            cumulative_ghgs=91493.592,
            cumulative_pv_generation=36685.0,
            diesel_capacity=3.0,
            diesel_times=0.356,
            final_pv_size=19.0,
            final_storage_size=20.227,
            initial_pv_size=20.0,
            initial_storage_size=25.0,
            lcue=1.179,
            renewables_fraction=0.717,
            unmet_energy_fraction=0.011,
        )

Additional Information

Desktop

(please complete the following information)

Modifications

The code is being modified to introduce more integration tests. This has resulted in the issue being highlighted.

Additional context

No additional context is needed :smile:

BenWinchester commented 2 years ago

@hamishbeath , let me know if you've got a spare moment what your thoughts on this rounding error might be, whether it's something you've hit before, and, if so, whether it is just a rounding error, or whether it's something more serious :smile:

hamishbeath commented 2 years ago

My hunch is that this is due to a rounding error. If it sometimes produces 0.099 rather than 0.1 and there are no larger errors occurring I would probably recommend leaving it as it is, I will defer to @phil-sandwell on this though.

BenWinchester commented 2 years ago

This is potentially due to having a one-year simulation which results in the diesel times being rounded to the nearest 1/365th, or, 0.00273973