Properly overload show#569
Conversation
|
I thought a bit of a structure and here are the ideas. 1. A new dispatch routerEvery abstract type (the “most upper one in the Hierarchy”) implements a 3-arg show (for the Manopt.jl/src/plans/solver_state.jl Lines 18 to 25 in b418aa3 Does this for all states 2. a new dispatch router for the status summary
3. new 2-arg show methodsWhat is now needed, besides a few more functions from 1 are the shorter ExampleI did write a first draft for Open points
Let me know what you think. If this is reasonable, then I would propose to edit your first post slowly and go through all states, problems, objectives, line searches,... and unify this. |
|
I think it would be more general to have the basic method to implement be the one with
The short form of states should rarely be displayed to users, to me the important parts are:
|
The “get similar object” would not easily work for the functions, since I can either print them nice as |
That is actually a bit complicated, since the While the (this could end in “call this factory with a manifold and you get an actual Armijo linesearch (stepsize).” The reason it is this way is ease of use when calling constructors. |
Some people might store the factory in their code somewhere, so it can print from there. I sometimes do that myself.
Yes, that's why I consider it only a nice-to-have. If anonymous functions are stored inside, that's a great example of where we can forget about copy-pasting.
Yes, these examples are fine.
Yes, it's perfectly fine to include factory call corresponding to the line search state but I'd like to see that the object is a state in the description. |
|
Then I think we agree. And sure the long forms I am fine with stating a bit more precise that the Then I think I have a reasonable overview about the things to do. Once I finish parts, I will slowly populate a list in the initial post to keep track of the progress. Thanks for the idea to unify this and for the discussions. |
|
For the human readable variant ( I also filled the list above for states / objectives and problems already and will work through them slowly next. |
…ses to now be status_summaries,
and reduce number of lines in a few places.
…t of twiddling in vector functions)
|
Status update: It seems there are only 6 step sizes missing. Step sizes currently take a bit of time, since I unify them in their promotion of real types (we had a few manual fixes for single fields, we will get that for all fields now) – and the last 6 ones are some with several fields. But at least it is slowly closing in going through all show/repr-s After that it is just quite a few tests for the new show methods and a few status_summaries that have to be written. edit: I wrote the remaining ones today. The rest of this PR is to get code coverage back up; looks like mostly checking that the show methods all print the right constructor (maybe it is enough to check that the function name is correct). |
|
Nice, hopefully there won't be any more surprises here 🙂 |
|
Since tests and docs are at least not failing it is hopefully just working through the remaining code cov, yes. |
Now logic in the Manopt universe is fixed again.
# Conflicts: # Changelog.md
|
LGTM 👍 (I can't issue a Github-approval because I've opened this PR, despite you doing vast majority of work here). |
|
I diverted the PR to be collected on a |
This is a WIP sketch for #560 .
Also fixes a few minor issues ChatGPT noticed.
In general the idea is as follows:
Base.show(io::IO, ::MIME"text/plain", x)for all elementsxfrom Manopt, that generically either prints thestatus_summaryin the multiline case orshow(io,x)otherwiseshow(io,x)to print (just) a nice constructorstatus_summary(x; context = :default)to print a human-readablecontext = :inline)context = :short)xshould be thecontext = :defaultstatus_summary(io, x; context = ;default)that directly writes ontoioand by default calls the normal one and writes that.(methods can switch this behaviour that the io generates text and the other materialises of course, then both have to be implemented)
The first has to be introduced for every main point (abstract type) below, and both show and status have to be checked for all concrete subtypes.
📋
For the abstract super types, the check indicates, that a 3-arg show for multiline text/html has been implemented to distinguish the human-readable
status_summaryand the short 2-arg show, “...” indicates, that the list is not yet complete.ConstrainedManoptProblemDefaultManoptProblemManopt.Test.DummyProblem, skipped for now, since this is only for testing and the use to tests its show does not seem necessary)TwoManifoldProblemVectorBundleManoptProblem<: AbstractManifoldObjective)ScaledManifoldObjectiveManifoldConstrainedSetObjectiveSymmetricLinearSystemObjectiveManopt.ReturnManifoldObjectiveScaledManifoldObjectiveSimpleManifoldCachedObjectiveManifoldCostObjectiveManifoldProximalGradientObjectiveManifoldProximalMapObjectiveManifoldSubgradientObjectiveAdaptiveRegularizationWithCubicsModelObjectiveTrustRegionModelObjectiveManifoldAlternatingGradientObjectiveManifoldDifferenceOfConvexObjectiveManifoldDifferenceOfConvexProximalObjectiveManifoldStochasticGradientObjectivePrimalDualManifoldSemismoothNewtonObjectiveNonlinearLeastSquaresObjective(this one is a bit inconsistent in naming – maybe also the two models above)ConstrainedManifoldObjectiveEmbeddedManifoldObjectiveManifoldCachedObjectiveManifoldCountObjectiveManifoldFirstOrderObjectiveManifoldHessianObjectiveManopt.ReturnManifoldObjectivePrimalDualManifoldObjectiveSimpleManifoldCachedObjectiveManopt.Test.DummyDecoratedObjective, skipped for now, since unlikely to require show/repr)<: AbstractManoptSolverState) - for all states only new show methods and testing missing.InteriorPointNewtonStateTruncatedConjugateGradientStateAlternatingGradientDescentStateConjugateGradientDescentStateFrankWolfeState(postponed for now)LevenbergMarquardtStateProximalPointStateQuasiNewtonStateStochasticGradientDescentStateVectorBundleNewtonStateAdaptiveRegularizationStateConjugateResidualStateConvexBundleMethodStateCyclicProximalPointStateDouglasRachfordStateLanczosStateAugmentedLagrangianMethodStateDifferenceOfConvexProximalStateDifferenceOfConvexStateExactPenaltyMethodStateTrustRegionsStateManopt.CMAESStateManopt.ClosedFormSubSolverStateManopt.ReturnSolverStateManopt.Test.DummyStateMeshAdaptiveDirectSearchStateNelderMeadStateParticleSwarmStateProximalBundleMethodStateProximalGradientMethodStateStepsizeStateSubGradientMethodStateDebugSolverStateGradientDescentStateRecordSolverStateDirectionUpdateRuleManopt.AverageGradientRuleManopt.ConjugateDescentCoefficientRuleManopt.ConjugateGradientBealeRestartRuleManopt.DaiYuanCoefficientRuleManopt.DirectionUpdateRuleStorageManopt.FletcherReevesCoefficientRuleManopt.HagerZhangCoefficientRuleManopt.HestenesStiefelCoefficientRuleManopt.HybridCoefficientRuleManopt.IdentityUpdateRuleManopt.LiuStoreyCoefficientRuleManopt.MomentumGradientRuleManopt.NesterovRuleManopt.PolakRibiereCoefficientRuleManopt.PreconditionedDirectionRuleManopt.SteepestDescentCoefficientRuleManopt.AlternatingGradientRuleManopt.StochasticGradientRuleStepsize(just missing the human readablestatus_summary)ArmijoLinesearchStepsizeAdaptiveWNGradientStepsizeAffineCovariantStepsizeConstantStepsizeDecreasingStepsizeDistanceOverGradientsStepsizeDomainBackTrackingStepsizeLineSearchesStepsizeNullStepBackTrackingStepsizePolyakStepsizeProximalGradientMethodBacktrackingStepsizeWolfePowellLinesearchStepsizeWolfePowellBinaryLinesearchStepsize<: StoppinCriterion)StopWhenBestCostInGenerationConstantStopWhenCovarianceIllConditionedStopWhenCriterionWithIterationConditionStopWhenCurvatureIsNegativeStopWhenEvolutionStagnatesStopWhenFirstOrderProgressStopWhenModelIncreasedStopWhenPopulationCostConcentratedStopWhenPopulationDivergesStopWhenPopulationStronglyConcentratedStopWhenRelativeResidualLessStopWhenResidualIsReducedByFactorOrPowerStopWhenSwarmVelocityLessStopWhenTrustRegionIsExceededStopAfterStopAfterIterationStopWhenAllStopWhenAllLanczosVectorsUsedStopWhenAnyStopWhenChangeLessStopWhenCostChangeLessStopWhenCostLessStopWhenCostNaNStopWhenEntryChangeLessStopWhenGradientChangeLessStopWhenGradientMappingNormLessStopWhenGradientNormLessStopWhenIterateNaNStopWhenKKTResidualLessStopWhenLagrangeMultiplierLessStopWhenPollSizeLessStopWhenPopulationConcentratedStopWhenProjectedGradientStationaryStopWhenRepeatedStopWhenSmallerOrEqualStopWhenStepsizeLessStopWhenSubgradientNormLessAbstractSolverAction(andDebugActionas well asRecordAction))DebugCallbackDebugChangeDebugCostDebugDividerDebugDualChangeDebugDualResidualDebugEntryDebugEntryChangeDebugEveryDebugFeasibilityDebugGradientDebugGradientChangeDebugGradientNormDebugGroupDebugIfEntryDebugIterateDebugIterationDebugMessagesDebugPrimalDualResidualDebugPrimalResidualDebugProximalParameterDebugStepsizeDebugStoppingCriterionDebugTimeDebugWarnIfCostIncreasesDebugWarnIfCostNotFiniteDebugWarnIfFieldNotFiniteDebugWarnIfGradientNormTooLargeDebugWarnIfLagrangeMultiplierIncreasesDebugWarnIfStepsizeCollapsedDebugWhenActiveRecordChangeRecordCostRecordEntryRecordEntryChangeRecordEveryRecordGradientRecordGradientNormRecordGroupRecordIterateRecordIterationRecordProximalParameterRecordStepsizeRecordStoppingReasonRecordSubsolverRecordTimeRecordWhenActiveLowerTriangularAdaptivePollDefaultMeshAdaptiveDirectSearchNelderMeadSimplex