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

Implement serialization to YAML format #11

Closed
speth opened this issue Dec 4, 2019 · 2 comments
Closed

Implement serialization to YAML format #11

speth opened this issue Dec 4, 2019 · 2 comments
Labels
work-in-progress An enhancement that someone is currently working on

Comments

@speth
Copy link
Member

speth commented Dec 4, 2019

Abstract

I am working on adding the ability to generate a YAML input which defines the species, reactions, and phase information that define a set of Cantera objects.

Motivation

It is possible to create Cantera objects (species, reactions, phases) dynamically, i.e. without using an input file. However, there is currently no way to save the definition of such objects for later use. Some possible uses for this feature include combining different mechanisms, generating reduced mechanisms, and performing parameter optimization on a mechanism.

Description

Like the creation of Cantera objects from YAML input, serialization is handled using the AnyMap class as an intermediary. Much of the implementation is essentially the reverse of the code which is used to set up objects using YAML input.

Alternatives

The introduction of the YAML format makes implementing this feature significantly easier and more general than an XML or CTI implementation would have been, due to the use of an existing, fully-featured library for reading and writing YAML files.

References

@ischoegl
Copy link
Member

ischoegl commented Jul 6, 2020

@speth ... copying from Cantera/cantera#881 as a discussion of auxiliary/custom fields is broader than the note/description controversy.

My current draft implementation provides a Python data structure made of simple types (e.g. nested maps and lists of strings and numbers) which correspond to the YAML entry that would recreate that same object. This includes both the fields used by Cantera as well as those that are not.

In terms of YAML, I see the appeal of being fully flexible, but am afraid that this will result in clutter, especially if core-Cantera fields are difficult to differentiate from custom fields. Also, doesn't this approach mean that there will be a lot of redundant information (i.e. information stored by both object and AnyMap/AnyValue)? Would it make sense to populate values using a AnyMap.pop (Python dictionary inspired) rather than AnyMap.at, and store what's left over as an AnyMap custom? For the reverse, you could re-populate an AnyMap with class variables before emitting to YAML? I admit that a lot of this depends on personal coding style, but as mentioned above, I believe there is a need to differentiate essential fields from auxiliary ones.

@ischoegl
Copy link
Member

This is presumably closed via Cantera/cantera#984.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work-in-progress An enhancement that someone is currently working on
Projects
None yet
Development

No branches or pull requests

2 participants