Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite ensure_cpg_file function to prevent frequent file writing #3673

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

yiqiaowang-arch
Copy link

@yiqiaowang-arch yiqiaowang-arch commented Oct 17, 2024

Describe the PR
The original ensure_cpg_file function was called very frequently whenever get_zone_geometry is used. Particularly, when using the energy potential - photovoltaic-thermal panels functionality. In each separate PVT calculation, this function was called around 12 times.

The original implementation of ensure_cpg_file is to just write zone.cpg file to desired content: "ISO-8859-1". When using a cloud drive, for example, OneDrive, to sync the scenarios, such frequent writing will cause OneDrive to sync this .cpg file constantly. Sometimes this cloud drive sync will block CEA to write it, causing PermissionError when trying to write this file again, forcing CEA to exit the current batch simulation. For example, my batch of PVT simulation stops at 1728/1752, and it's hard to find out which one has not been simulated yet...

A straightforward solution will be first open the file with read access, check if the content is already there. If so, there's no need to change anything and just end the function; if not, then the file is re-opened using with, and this time the correct content is written into the file.

To Test
I have tested it on my own computer and make sure that this function worked correctly with both correct and wrong content in zone.cpg after several runs. However, there's not yet a systematic testing on all cases.

Steps to test this PR:

  1. open zone.cpg in /inputs/geometry folder;
  2. delete contents inside the .cpg file, save and close;
  3. do a demand analysis for a building, or any other functionality that calls get_zone_geometry;
  4. After the calculation, open the zone.cpg file again, confirm that the content is ISO-8859-1.
  5. This test confirms that the goal of this function, which is still to ensure the encoding, is still working.

Expected behaviour
Behaviour should not be affected.

Extra Data Needed
None.

in order to read the file first before asking for writing permission
@yiqiaowang-arch yiqiaowang-arch marked this pull request as ready for review October 17, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant