Skip to content

Silence polymake's informational messages - #27

Merged
fingolfin merged 1 commit into
masterfrom
quiet-polymake
Aug 16, 2026
Merged

fingolfin merged 1 commit into
masterfrom
quiet-polymake

Conversation

@fingolfin

@fingolfin fingolfin commented Aug 16, 2026

Copy link
Copy Markdown
Member

polymake prints the credits of third-party software it uses, and notes when it converts a data file to a newer format. These went straight to the terminal, interleaved with GAP output:

gap> Polymake(permutahedron,"VOLUME");
polymake: upgrading /var/folders/.../poly2084 from old plain file format
polymake: used package ppl
  The Parma Polyhedra Library ...
  http://www.cs.unipr.it/ppl/

3

Now:

gap> Polymake(permutahedron,"VOLUME");
3

Fixes #23. Stacked on #26.

Why not just honour the user's polymake config

As #23 notes, these messages can be turned off in ~/.polymake/settings --
but polymaking passes --config-path "", which disables all user
configuration, so those settings never apply.

Dropping the flag is tempting: with an empty config path
_applications::configured is empty, so polymake re-runs every CONFIGURE
block on every call. But measured, that is worth only about 40ms of the
~850ms a call takes -- the bulk is loading the polytope rules, which happens
whatever the config path is. And dropping it would make polymake create and
write ~/.polymake, fail where $HOME is unwritable (sandboxed distro
builds), and make results depend on the user's prefer settings.

Instead the script sets $Polymake::User::Verbose::credits and ::files
directly, which works whatever the config path is -- polymake's own test
harness does the same (Test/Environment.pm:65, Test/BigObject.pm:165).
Users who do want their configuration honoured can now set
PolymakeConfigPath to "user".

New preferences

preference default
PolymakeQuiet true suppress polymake's informational messages
PolymakeConfigPath "" value for polymake's --config-path
PolymakePreferences [ ] rule preferences, e.g. [ "*.convex_hull cdd" ]

Capturing stderr

pm_script_arg.pl gained an option head (--stderr FILE, --quiet,
--prefer EXPR, -- terminator). Reassociating the STDERR glob catches
dbg_print as well as err_print/warn_print, which write to
$Polymake::console, and polymake's own fatal error handler.

GAP reads the file back, so diagnostics are no longer lost. They are shown at
InfoPolymaking level 2, and on failure become part of the error message and
of POLYMAKE_LAST_FAIL_REASON:

gap> Polymake(p, "NO_SUCH_PROPERTY");
Error, polymake returned an error (error code 1)
polymake:  ERROR: ... Can't locate object method "NO_SUCH_PROPERTY" via
package "Polymake::polytope::Polytope__Rational"

Previously that was just polymake returned an error (error code 1).

Two bugs found along the way

  • UpdatePolymakeFailReason was called after Error, so
    POLYMAKE_LAST_FAIL_REASON was only ever set if the user resumed from the
    break loop.
  • The multi-keyword branch tested returnedstring <> [] on the result record
    rather than on returnedstring.string, so it was always true.

Notes on the implementation

prefer_now does not work under --script: $Polymake::User::application is
a stub whose prefs are unset, so it dies with Can't call method set_temp_preference on an undefined value. The preference is applied to the
object's own application instead, with Mode::create rather than the usual
Mode::strict -- strict sets $Prefs->changed, which would make polymake
rewrite the user's settings file when a config path is in use.

Testing

  • tst/testall.g: 0 failures.
  • Verified by hand that the output is silent by default, that
    PolymakeQuiet := false brings the messages back, that a failing call
    populates POLYMAKE_LAST_FAIL_REASON with polymake's own message, and that
    PolymakePreferences really switches backend (the credit line changes from
    used package ppl to used package cdd, and the results change with it).

🤖 Generated with Claude Code

@codecov

codecov Bot commented Aug 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.00%. Comparing base (47bdc93) to head (918c011).

Files with missing lines Patch % Lines
lib/construct.gi 67.64% 11 Missing ⚠️
lib/userpref.gi 97.56% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #27      +/-   ##
==========================================
+ Coverage   70.74%   72.00%   +1.26%     
==========================================
  Files          15       15              
  Lines         810      868      +58     
==========================================
+ Hits          573      625      +52     
- Misses        237      243       +6     
Files with missing lines Coverage Δ
lib/userpref.gi 87.28% <97.56%> (+4.73%) ⬆️
lib/construct.gi 73.63% <67.64%> (+0.44%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from userprefs to master August 16, 2026 21:45
polymake reports the credits of third-party software it uses and notes when it
converts a data file to a newer format. These messages went straight to the
terminal, interleaved with GAP output.

They cannot be turned off through polymake's own settings because polymaking
passes --config-path "", which disables all user configuration. Instead set
$Polymake::User::Verbose::credits and ::files in pm_script_arg.pl, which works
whatever the config path is. This is controlled by the new PolymakeQuiet
preference and on by default.

Two further preferences: PolymakeConfigPath, for users who do want their
polymake configuration honoured, and PolymakePreferences, to pass rule
preferences such as "*.convex_hull cdd".

The script now also redirects stderr to a file that GAP reads back, so polymake
diagnostics are no longer lost: they are shown at InfoPolymaking level 2, and
on failure become part of the error message and of POLYMAKE_LAST_FAIL_REASON,
which used to report just an exit code.

Along the way, two bugs in the failure paths of Polymake:
- UpdatePolymakeFailReason was called after Error, so it only ever ran if the
  user resumed from the break loop
- the multi-keyword branch tested `returnedstring <> []` on the result record
  rather than on `returnedstring.string`, which was always true

Fixes #23.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fingolfin
fingolfin merged commit 47eb6ec into master Aug 16, 2026
5 checks passed
@fingolfin
fingolfin deleted the quiet-polymake branch August 16, 2026 21:51
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.

Allow to silence certain polymake messages to stderr

1 participant