Skip to content

Load CoolProp without its superancillaries - #49

Merged
jtravs merged 4 commits into
mainfrom
perf/coolprop-no-superancillaries
Nov 17, 2026
Merged

jtravs merged 4 commits into
mainfrom
perf/coolprop-no-superancillaries

Conversation

@jtravs

@jtravs jtravs commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

CoolProp 8.0.0 builds the superancillaries of all of its ~120 fluids the first time it loads. That is 0.43 s of its 0.46 s load, and every solprop run with a built-in gas pays it (real-gas density, flow viscosity). With COOLPROP_DISABLE_SUPERANCILLARIES_ENTIRELY set, the load takes 0.067 s.

Changes (TC-1096)

  • _coolprop() sets the variable for the import alone, then removes it so child processes don't inherit it. It hides CoolProp's stdout notice about it, flushing C's buffers before and after the redirect.
  • The user keeps control:
    • if the variable is already set, it is left alone and the notice shows;
    • importing CoolProp before optmat keeps the superancillaries.
  • _update_gas tells CoolProp a state below the critical temperature is the vapour (iphase_gas); every caller has already checked that. Without superancillaries, CoolProp's own phase search refuses pressures below the triple point's, so every gas's round-trip test failed just above the triple point.
  • EVALUATION_VERSION of optmat.gas.eos is raised to 2. 57 golden identities are re-recorded (equations of state, mixtures, transport and air models). No golden value changed.

Checked against 0.9.1 (with superancillaries)

  • Densities: every gas, 12 temperatures from the triple point to 600 K and a fixed grid of 40 pressures from 100 Pa to 200 bar, 5924 states in all. Every density is bitwise the same.
  • Critical temperatures: CoolProp now reports each equation's stated value instead of the superancillary's critical point.
    • Oxygen's goes from 154.599 K to the published 154.581 K (1.2e-4). Between the two it is now supercritical: its domain there ends at 800 bar instead of the vapour pressure.
    • Hydrogen's moves by 2.0e-5; the others' by at most 2.1e-6.
  • Saturation pressures, sampled at 300 temperatures per gas, denser towards the critical point:
    • more than 1 K below the critical point they move by at most 7.1e-11; at oxygen's triple point, by 2.0e-9;
    • within 1 K, by up to 6.5e-8 (hydrogen);
    • within 60 µK of helium's critical point and 4.4 µK of SF6's, the solve is off by more than 1e-6, and for helium it can raise CoolProp's own ValueError.

Tests: tests/test_coolprop_loading.py keeps the density and saturation comparison and checks:

  • that CoolProp loads without superancillaries;
  • that it prints nothing;
  • that the user's choices are kept;
  • that child processes don't inherit the variable;
  • that C output written earlier still reaches stdout.

Measured in a solprop capillary run (helium, RDW example): the recipe build takes 0.26 s instead of 0.52 s. solprop will need a release with this and a new pin.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HAYtF6Xu3t9Fr5Spcc6Y4i

CoolProp builds the superancillaries of all of its fluids when it first loads,
0.43 s of its 0.46 s load. optmat now sets COOLPROP_DISABLE_SUPERANCILLARIES_ENTIRELY
before importing it (unless already set), hides CoolProp's stdout notice of it, and
tells CoolProp a subcritical state is the vapour (iphase_gas), as every caller has
checked, since without superancillaries CoolProp's own phase search refuses the
domain's states just above the triple point. Densities are bitwise unchanged against
0.9.1 over every gas's domain; saturation pressures move by at most 3e-11 (oxygen at
its triple point 2e-9). TC-1095.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HAYtF6Xu3t9Fr5Spcc6Y4i
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T09:25:31.057265Z 69b77b2 PR opened
🔒 Security Review ✅ Completed 2026-11-17T09:27:08.864043Z 69b77b2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 69b77b2205

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/optmat/gas/eos.py
Comment on lines +135 to +136
sys.stdout.flush()
saved = os.dup(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Flush native output before redirecting stdout

When stdout is redirected to a pipe or file, native libraries can have buffered output pending before the first real-gas call. sys.stdout.flush() only flushes Python's stream, so that native output remains buffered until _flush_c_streams() runs while descriptor 1 points to /dev/null, silently discarding the caller's output along with CoolProp's notice. This is reproducible by calling libc printf before entering _quiet_stdout(). Flush the native streams before redirecting descriptor 1 as well as before restoring it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7043d9b: _quiet_stdout now flushes C's buffers before redirecting descriptor 1 as well as before restoring it. test_native_output_written_before_the_block_is_kept checks it with libc printf; it fails without the fix.

@read-the-docs-community

read-the-docs-community Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

jtravs and others added 2 commits November 17, 2026 09:58
…n standard output

The switch stayed in os.environ after the import, so a child process took it for the
user's and CoolProp printed its notice there (three tests that read a child's output
failed in CI); it is now removed after the import. C's buffers are also flushed before
descriptor 1 is redirected, so native output written earlier is not discarded (review).
The register entry is TC-1096: main took TC-1095 for BBO.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HAYtF6Xu3t9Fr5Spcc6Y4i
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

… move without superancillaries

Without superancillaries CoolProp reports an equation's stated critical temperature
rather than its superancillary's critical point (oxygen 154.581 K for 154.599 K; others
within 2e-5), a field of every equation's identity, and its saturation solve is less
precise close to the critical point (up to 6.5e-8 within 1 K; worse within tens of
microkelvin of helium's and SF6's). The macOS gate's golden identities failed on it.
The maintainer chose to raise EVALUATION_VERSION; 57 golden identities re-recorded,
no golden value changed. TC-1096, the changelog fragment and the manual now say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HAYtF6Xu3t9Fr5Spcc6Y4i
@jtravs
jtravs merged commit d5603f3 into main Nov 17, 2026
6 checks passed
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