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

Add (de)serialization to all settings classes #535

Open
dokempf opened this issue Feb 5, 2025 · 0 comments
Open

Add (de)serialization to all settings classes #535

dokempf opened this issue Feb 5, 2025 · 0 comments
Labels
python-api Related to the new Helios++ Python API sustainable h++ Part of the sustainable HELIOS++ project

Comments

@dokempf
Copy link
Collaborator

dokempf commented Feb 5, 2025

All settings classes should be trivially serializable to JSON/YAML etc. For that purpose, it would make sense to extend the model base class with these capabilities. I would propose to add the following:

class SomeSettings:
	def to_dict(self) -> dict:
		# Return a Python dictionary with the class

	@classmethod
	def from_dict(cls, data: dict):
		# Construct from a dictionary

	def to_yaml(self, filename: Path):
		# Write a YAML file, using to_dict

	@classmethod
	def from_yaml(cls, filename: Path):
		# Create from YAML file, using from_dict

	def to_json(self, filename: Path):
		# Write a JSON file, using to_dict

	@classmethod
	def from_json(cls, filename: Path):
		# Create from JSON file, using from_dict

I do not think the particular choice of YAML or JSON is relevant here, might as well allow both. The import bit is that the writing and parsing is implemented in exactly one place to minimize the overhead of having both.

@dokempf dokempf added python-api Related to the new Helios++ Python API sustainable h++ Part of the sustainable HELIOS++ project labels Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python-api Related to the new Helios++ Python API sustainable h++ Part of the sustainable HELIOS++ project
Projects
None yet
Development

No branches or pull requests

1 participant