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

Improve YAML output formatting #1128

Closed
ischoegl opened this issue Oct 23, 2021 · 2 comments · Fixed by #1133
Closed

Improve YAML output formatting #1128

ischoegl opened this issue Oct 23, 2021 · 2 comments · Fixed by #1133

Comments

@ischoegl
Copy link
Member

ischoegl commented Oct 23, 2021

Problem description

As observed in #1112 (and likely elsewhere), some of the human-readable output generated by YAML emitters could be improved.

Steps to reproduce

The YAML output below can be produced using the new save method proposed for 1D objects (#1112), but the underlying implementation predates this PR (goes back to #984).

Behavior

There are three formatting issues documented thus far:

(1) Scalars / Rounding

As already pointed out in #984 (where serialization was initially introduced), there are some "floating point rounding issues [that] result in kind of ugly values". For example:

    tolerances:
      steady-abstol: 1.0e-09
      steady-reltol: 1.0e-04
      transient-abstol: 9.999999999999999e-12 # <-- should be 1.0e-11
      transient-reltol: 1.0e-04

I have not looked into details, but at least for scalar values there may be a way to catch these items.

(2) Vectors / Efficient use of space

Number blocks don't use horizontal space efficiently; this may be addressed by changing:

    velocity: [0.7112641405849059, 0.7112641405822596, 0.7112641404451637,
    0.7112641377426332, 0.7112641104415781, 0.7112637339406135,
    0.7112617435453226, 0.7112560064702751, 0.7112322153842345,
    ...
    4.055246182368149, 4.055246182377726]

to

    velocity: [
      0.7112641405849059, 0.7112641405822596, 0.7112641404451637, 0.7112641377426332, 
      0.7112641104415781, 0.7112637339406135, 0.7112617435453226, 0.7112560064702751, 
      0.7112322153842345, 0.7111349509095231, 0.7109781680863129, 0.7106086071388092,
      ...
      4.055246182368149, 4.055246182377726]

which uses space more efficiently and also improves readability from a human perspective. Beyond, there is likely an optimized number of characters per line that prevents ragged output in most cases.

System information

  • Cantera version: 2.6
  • OS: any
  • Python/MATLAB/other software versions: any

Additional context

@ischoegl
Copy link
Member Author

Ad (2) ... stumbled across @speth's post on stackoverflow 😅

@ischoegl
Copy link
Member Author

ischoegl commented Oct 26, 2021

Looking over this some more, it appears that this

    velocity: [
    0.7112641405849059, 0.7112641405822596, 0.7112641404451637, 0.7112641377426332, 
    0.7112641104415781, 0.7112637339406135, 0.7112617435453226, 0.7112560064702751, 
    0.7112322153842345, 0.7111349509095231, 0.7109781680863129, 0.7106086071388092,
    ...
    4.055246182368149, 4.055246182377726]

is possible, but the leading indent is problematic. I located a couple of YAML::Emitter settings in yaml-cpp, but nothing changes the output.

Breaking the line as indicated above may look nicer in some cases, but I don't think it's a big enough improvement (if at all) to warrant implementation.

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 a pull request may close this issue.

1 participant