Scoped configuration: private API
Package-level configuration values (pretty-printing collapse, fuzzy-suggestion distance, equation-parser resource caps, the scenario-fill share) are held in thread-safe ScopedConfig holders: a set_*! setter swaps the global default atomically, a with_* helper overrides it for the dynamic extent of a call (task-scoped, automatically restored), and per-project defaults can be seeded at load time via Preferences.jl.
PortfolioOptimisers.RESOURCE_LIMITS — Constant
RESOURCE_LIMITS = ScopedConfig(ResourceLimits())Default global resource caps for the sampling- and sweep-based estimators, guarding the config→allocation trust boundary against memory and compute exhaustion. Read as RESOURCE_LIMITS[]; the defaults may be seeded per project at load time via the "max_n_sim" / "max_n_subsets" / "max_frontier" / "max_bins" / "max_hop_count" / "max_search_grid" / "max_ep_grid" preferences (see apply_preferences!).
Related
PortfolioOptimisers.COMPACT_SHOW — Constant
Global control for collapsing large nested structs in @define_pretty_show output.
Holds one of:
false: collapsing disabled; nested structs always expand fully.true: collapsing enabled with an automatic, terminal-size-derived line budget.n::Int: collapsing enabled with a fixed line budget ofn.
Held in a ScopedConfig: set the global default via set_compact_show!, override per scope via with_compact_show, and read (together with the per-call :po_compact IO property) by compact_show_budget. The default may be seeded per project at load time via the "compact_show" preference (see apply_preferences!).
PortfolioOptimisers.SHOW_NOTHING_FIELDS — Constant
SHOW_NOTHING_FIELDS = ScopedConfig(ShowNothingFields(false, Dict{Symbol, Bool}()))Global control for whether @define_pretty_show renders a field that holds nothing.
The shipped default hides such a field, because a reader at the REPL wants the fields that carry a value. The documentation build turns them on with set_show_nothing_fields!(true), beside its set_compact_show!(false) call, so a rendered docstring shows the complete type. Read as SHOW_NOTHING_FIELDS[] by pretty_show_fields; the default may be seeded per project at load time via the "show_nothing_fields" and "show_nothing_fields_by_type" preferences (see apply_preferences!).
Related
PortfolioOptimisers.STRING_DISTANCE — Constant
STRING_DISTANCE = ScopedConfig(StringDistanceConfig(StringDistances.Levenshtein(), 0.7))Default string distance configuration for fuzzy "did you mean?" suggestions appended to "variable not in asset universe" messages by did_you_mean. Read as STRING_DISTANCE[]; the defaults may be seeded per project at load time via the "suggestion_distance" / "suggestion_min_score" preferences (see apply_preferences!).
Related
PortfolioOptimisers.EQUATION_LIMITS — Constant
EQUATION_LIMITS = ScopedConfig(EquationLimits(4096, 256))Default global resource caps for equation parsing, guarding the string→AST trust boundary against a stack-exhaustion denial of service. Read as EQUATION_LIMITS[]; the defaults may be seeded per project at load time via the "equation_max_length" / "equation_max_depth" preferences (see apply_preferences!).
Related
PortfolioOptimisers.ScopedConfig — Type
mutable struct ScopedConfig{T}Thread-safe holder for a package-level configuration value, combining a persistent global default with a task-scoped override.
Reads go through cfg[], which returns the innermost active scoped override when inside a with_* block, otherwise the global default. The default is an @atomic field swapped as a whole — a set_*! call is a single atomic store, so concurrent readers (e.g. the FLoops.@floop loops inside meta-optimisers) can never observe a torn or partially-updated configuration. The scoped override is a Base.ScopedValues.ScopedValue: it is inherited by tasks spawned inside the scope, restored automatically when the scope exits, and invisible to unrelated concurrent tasks.
Configs held this way store immutable structs (or bits values); changing any knob builds a new value and swaps it in, never mutates in place.
Used by COMPACT_SHOW, SHOW_NOTHING_FIELDS, STRING_DISTANCE, EQUATION_LIMITS and RESOURCE_LIMITS; their global defaults are set via the set_*! setters, scoped overrides via the with_* helpers, and load-time per-project defaults via Preferences.jl (see apply_preferences!).
Related
PortfolioOptimisers.ResourceLimits — Type
struct ResourceLimitsGlobal resource caps for the sampling- and sweep-based estimators, guarding the config→allocation trust boundary against memory and compute exhaustion.
Draw counts, subset counts, frontier-sweep lengths and histogram bin counts are untrusted configuration integers (config files, tuning grids, UI): each directly multiplies an allocation, and in the subset and frontier cases a whole optimisation. Their own constructors only bound them from below (n_sim > 0, n_subsets >= 2, N > 0, bins > 0), so an absurd value — a stray extra digit, a mis-scaled sweep — is accepted and the process is killed by the OOM killer rather than told what went wrong. These caps fail closed with a typed DomainError at the point the value is resolved.
There is one cap per sink, each named to mirror the field it guards. Reuse across sinks is deliberately avoided: a linear cap cannot bound a quadratic sink, which is why the bins × bins histogram gets its own max_bins rather than sharing the linear draw cap.
The values are conservative static defaults, deliberately far above legitimate use: they exist to convert an OOM kill into a typed error, not to second-guess a sizing choice. Immutable; held in the RESOURCE_LIMITS ScopedConfig. Set the global default via set_resource_limits!, override per scope via with_resource_limits. Prefer the keyword constructor ResourceLimits(; …) — the seven caps are same-typed and four share the value 100_000, so positional construction is error-prone.
Fields
max_n_sim: Maximum Monte-Carlo or bootstrap draws (n_sim) accepted byNormalUncertaintySetandARCHUncertaintySet. The default is1_000_000. Each draw stores anN × Ncovariance, so the backing array isN² · n_simelements: at 20 assets the default cap already permits a 3.2 GB request, while the shippedn_simis3_000. Memory-bound.
max_n_subsets: Maximum resampled asset subsets (n_subsets) accepted bySubsetResamplingandMultipleRandomised. The default is100_000. This cap bounds compute far more than memory, because every subset runs a full inner optimisation, so it sits far above any realistic sweep (the shipped default is2) yet well below a value that would wedge a session for days.
max_frontier: Maximum efficient-frontier sweep points accepted by theFrontieralgorithm ofMeanRiskandNearOptimalCentering. The default is100_000. Likemax_n_subsetsit is compute-bound, because every point runs a full inneroptimise_JuMP_model!solve, so it mirrors that ceiling; the shippedFrontierdefault isN = 20. It is enforced twice:Frontier's constructor caps theNof one bound, andassert_frontier_sweep_capcaps the product across every swept return term and every swept risk measure at Model Assembly, because the sweep is anIterators.productandkbounds ofNpoints costN^ksolves.
max_bins: Maximum histogram bins accepted byMutualInfoCovarianceandVariationInfoDistance. The default is10_000. The joint histogram is abins × binsweights matrix built per asset pair, so this bounds a quadratic memory allocation:10_000²cells is about 800 MB per histogram, below OOM yet far above the roughly 50-bin range that legitimate binning produces.
max_hop_count: Maximum hop count (n) accepted byHopCount. The default is100_000. Three readers sumA^ioveri in 0:n, so the sink is linear innatN³flops a power, and a largenwedges the session on compute rather than on memory. Likemax_n_subsetsit is compute-bound and mirrors that ceiling; the shipped default isn = 1. The cap is read inHopCount's constructor, which is also whereresolve_separationsends a rule's answer, so one check covers the stated value and the computed one alike.
max_search_grid: Maximum search-grid candidates accepted byGridSearchCrossValidationandRandomisedSearchCrossValidation. The default is100_000. Every candidate runs a full cross-validated fit, so this is compute-bound likemax_n_subsets. The grid is anIterators.productmaterialised bycollect, sokparameters ofNvalues costN^kcandidates: the cap is asserted on the product byassert_search_grid_capwhere the grid is formed, because a per-parameter check can never see it.
max_ep_grid: Maximum grid points (K) accepted byGridEntropicValueatRiskViewandGridRelativisticValueatRiskView. The default is10_000. Every grid point is one binary variable of the mixed-integer program an upper-bound or equality view builds, and one dense row over theTposterior probabilities, so the sink is a mixed-integer one: linear inKin memory atK · Tcoefficients, and a branch-and-bound tree overKbinaries in compute. It therefore sits far below the compute ceilings that bound a plain solve, and far above the shippedK = 11.
Constructors
ResourceLimits(max_n_sim::Integer, max_n_subsets::Integer, max_frontier::Integer, max_bins::Integer, max_hop_count::Integer, max_search_grid::Integer, max_ep_grid::Integer) -> ResourceLimitsResourceLimits(; max_n_sim::Integer = 1_000_000, max_n_subsets::Integer = 100_000, max_frontier::Integer = 100_000, max_bins::Integer = 10_000, max_hop_count::Integer = 100_000, max_search_grid::Integer = 100_000, max_ep_grid::Integer = 10_000) -> ResourceLimitsKeywords correspond to the struct's fields.
Validation
max_n_sim > 0 && max_n_subsets > 0 && max_frontier > 0 && max_bins > 0 && max_hop_count > 0 && max_search_grid > 0 && max_ep_grid > 0.
Related
PortfolioOptimisers.ShowNothingFields — Type
struct ShowNothingFieldsConfiguration for whether @define_pretty_show renders a field that holds nothing.
Held in the SHOW_NOTHING_FIELDS ScopedConfig, and read by pretty_show_fields. Set the global default via set_show_nothing_fields!, override per scope via with_show_nothing_fields. The value is treated as immutable: a change builds a new value with a copied by_type and swaps it in, so a reader never observes a half-written table.
Fields
default: Whether a field that holdsnothingprints for a type that no per-name entry names. The shipped default isfalse, so anothingfield is hidden.
by_type: Per-name overrides, keyed on the bare name of a type. Atrueentry prints every declared field of that type, and afalseentry hides itsnothingfields, whateverdefaultholds and whatever the type's ownshow_fieldsmethod returns.
Constructors
ShowNothingFields(default::Bool, by_type::Dict{Symbol, Bool}) -> ShowNothingFieldsShowNothingFields(cfg::ShowNothingFields, name::Symbol, x::Union{Nothing, Bool}) -> ShowNothingFieldsThe second form copies cfg with one per-name entry changed: x sets the entry for name, and nothing removes it.
Related
PortfolioOptimisers.StringDistanceConfig — Type
struct StringDistanceConfigGlobal configuration for the fuzzy "did you mean?" suggestions appended to "variable not in asset universe" messages by did_you_mean.
Immutable; held in the STRING_DISTANCE ScopedConfig. Set the global default via set_string_distance!, override per scope via with_string_distance. Read by did_you_mean.
Fields
dist: Distance used to score a candidate name against the offending one. The default isStringDistances.Levenshtein().
min_score: Minimum normalised similarity a candidate must reach before it is suggested. The default is0.7. A value toward1keeps only a near-exact match, and a value above1disables suggestions entirely, which is what a meta-optimiser inner loop wants: an asset name legitimately absent from a cluster or a subset is not a typo and must draw no suggestion.
Constructors
StringDistanceConfig(dist::StringDistances.StringDistance, min_score::Real) -> StringDistanceConfigValidation
min_score > 0.StringDistances.findnearestnever suggests a candidate scoring exactly0, but any threshold at or below0admits every candidate with some nonzero similarity, so0and a negative value behave identically. Both defeat the info-leak-safe boundary by naming a real asset for a near-miss probe.
Related
PortfolioOptimisers.EquationLimits — Type
struct EquationLimitsGlobal resource caps for equation parsing, guarding the string→AST trust boundary against a stack-exhaustion denial of service.
Constraint, Black-Litterman view and entropy-pooling view strings are untrusted input (config files, spreadsheets, UI). They funnel through parse_equation, which calls Meta.parse and then walks the resulting expression tree recursively (eval_numeric_functions, collect_terms!, has_invalid_plus). Without a bound, a deeply nested string (e.g. tens of thousands of parentheses) produces an AST deep enough to exhaust the stack and take down the host process. These caps fail closed with a typed Meta.ParseError well before that point.
The values are conservative static defaults (portable across build and deployment machines, unlike a value auto-detected during precompilation). Immutable; held in the EQUATION_LIMITS ScopedConfig. Set the global default via set_equation_limits!, override per scope via with_equation_limits. See docs/adr/0027-cap-equation-parser-recursion.md.
Fields
max_length: Maximum number of characters in an equation string handed toMeta.parse. The default is4096. A legitimate linear constraint is short, so the bound sits far above any real constraint and far below the nesting depth that threatens the stack. A nesting depthdneeds at leastdcharacters, so the length cap also bounds the AST depth of the string form.
max_depth: Maximum expression-tree depth accepted by theExprform ofparse_equation. The default is256. That form receives a pre-built AST, which no length cap covers.
Constructors
EquationLimits(max_length::Integer, max_depth::Integer) -> EquationLimitsValidation
max_length > 0 && max_depth > 0.
Related
PortfolioOptimisers.set_default! — Function
set_default!(cfg::ScopedConfig{T}, x) -> Any
Atomically replace the global default of a ScopedConfig with x and return it. Does not affect any active scoped override.
Algorithm
- Convert
xtoT, the element type ofcfg, so that a failed conversion raises before anything is stored. - Store the converted
xintocfg.defaultin one atomic write, so that a concurrent reader sees either the old value or the new one and never a partial write.
Arguments
cfg: Configuration holder whose global default is replaced.x: New value, converted to the element typeTofcfg.
Returns
x::T: The stored value.
Related
PortfolioOptimisers.with_config — Function
with_config(f, cfg::ScopedConfig{T}, x) -> Any
Run f() with the ScopedConfig cfg overridden to x for the dynamic extent of the call, restoring the previous value on exit. Thread-safe: the override is task-scoped (inherited by tasks spawned inside f, invisible to concurrent tasks outside it).
Algorithm
- Convert
xtoT, the element type ofcfg. - Bind
cfg.scopedto the convertedxand runf()inside that binding, so that the binding is restored whenfreturns and whenfraises.
Arguments
f: Zero-argument function to run under the override.cfg: Configuration holder to override.x: Override value, converted to the element typeTofcfg.
Returns
- The value that
f()returns.
Related
PortfolioOptimisers.set_resource_limits! — Function
set_resource_limits!(; max_n_sim::Integer, max_n_subsets::Integer,
max_frontier::Integer, max_bins::Integer,
max_hop_count::Integer, max_search_grid::Integer,
max_ep_grid::Integer)Configure the global default resource caps read at the config→allocation trust boundary (see RESOURCE_LIMITS).
Raise them for a genuinely large machine-authored run on a machine sized for it, or lower them to tighten the boundary. Unspecified keywords keep their current default. The store is atomic (see ScopedConfig); for a temporary, task-scoped override use with_resource_limits.
Algorithm
- Default each keyword the caller omits to the field of the current global default, read atomically. A scoped override is not read, so the call configures the global default alone.
- Build a
ResourceLimitsfrom the seven keywords, which is where the validation below runs. - Store it as the global default of
RESOURCE_LIMITSthroughset_default!.
Arguments
max_n_sim::Integer: Maximumn_simaccepted by the uncertainty-set estimators.max_n_subsets::Integer: Maximumn_subsetsaccepted by the subset-resampling estimators.max_frontier::Integer: MaximumNaccepted by oneFrontier, and maximum total sweep points across every swept bound.max_bins::Integer: Maximumbinsaccepted by the mutual-information estimators.max_hop_count::Integer: Maximumnaccepted byHopCount, stated or resolved from a rule.max_search_grid::Integer: Maximum total candidates in a search cross-validation grid.max_ep_grid::Integer: MaximumKaccepted by the grid formulations of the entropic and relativistic value-at-risk views.
Validation
- Every cap is positive, enforced by
ResourceLimits.
Returns
lims::ResourceLimits: The new global default.
Related
PortfolioOptimisers.with_resource_limits — Function
with_resource_limits(f; max_n_sim::Integer = RESOURCE_LIMITS[].max_n_sim,
max_n_subsets::Integer = RESOURCE_LIMITS[].max_n_subsets,
max_frontier::Integer = RESOURCE_LIMITS[].max_frontier,
max_bins::Integer = RESOURCE_LIMITS[].max_bins,
max_hop_count::Integer = RESOURCE_LIMITS[].max_hop_count,
max_search_grid::Integer = RESOURCE_LIMITS[].max_search_grid,
max_ep_grid::Integer = RESOURCE_LIMITS[].max_ep_grid)Run f() with the resource caps (see RESOURCE_LIMITS) overridden for the dynamic extent of the call, restoring the previous caps on exit. Task-scoped and thread-safe (see ScopedConfig); the global default is untouched. Unspecified keywords inherit from the currently active value, so nested overrides compose.
Useful to raise the ceiling for one deliberately large run without loosening the boundary for other concurrent work. Note the cap is read where the value is resolved: n_sim, N, bins and K at estimator construction, n_subsets when the optimisation resolves its (possibly TimeDependent) schedule — so wrap the constructor call in the former cases and the optimise call in the latter.
Algorithm
- Default each keyword the caller omits to the field of the currently active value, so that a nested override inherits from the enclosing one instead of from the global default.
- Build a
ResourceLimitsfrom the seven keywords, which is where the validation below runs. - Run
f()withRESOURCE_LIMITSbound to that value throughwith_config.
Arguments
f: Zero-argument function to run under the override.max_n_sim::Integer: Maximumn_simaccepted by the uncertainty-set estimators.max_n_subsets::Integer: Maximumn_subsetsaccepted by the subset-resampling estimators.max_frontier::Integer: MaximumNaccepted by oneFrontier, and maximum total sweep points across every swept bound.max_bins::Integer: Maximumbinsaccepted by the mutual-information estimators.max_hop_count::Integer: Maximumnaccepted byHopCount, stated or resolved from a rule.max_search_grid::Integer: Maximum total candidates in a search cross-validation grid.max_ep_grid::Integer: MaximumKaccepted by the grid formulations of the entropic and relativistic value-at-risk views.
Validation
- Every cap is positive, enforced by
ResourceLimits.
Returns
- The value that
f()returns.
Related
PortfolioOptimisers.set_compact_show! — Function
set_compact_show!(x::Bool)
set_compact_show!(n::Integer)Configure whether @define_pretty_show collapses large nested structs.
set_compact_show!(false): disable collapsing (always expand fully).set_compact_show!(true): enable collapsing with an automatic, terminal-size-derived budget.set_compact_show!(n): enable collapsing with a fixed line budgetn.
Collapsing only ever applies to height-limited output (get(io, :limit, false)), i.e. the interactive REPL. Non-limited output (string, repr, file writes) always expands fully. The documentation build disables this so rendered docs keep full detail. Individual calls can override the global setting with the :po_compact IO property (false, true, or an Int).
Sets the global default (atomically; see ScopedConfig). For a temporary, task-scoped override use with_compact_show.
Algorithm
- Widen an
Integerargument toInt, so that the two methods store one of the two members of the stored union and never a third integer type. ABoolis stored unchanged. - Store the value as the global default of
COMPACT_SHOWthroughset_default!.
Arguments
x::Bool:falsedisables collapsing,trueenables it with the automatic budget.n::Integer: Fixed line budget, stored as anInt.
Returns
x::Union{Bool, Int}: The stored setting.
Related
PortfolioOptimisers.with_compact_show — Function
with_compact_show(f, x::Bool)
with_compact_show(f, n::Integer)Run f() with the COMPACT_SHOW collapsing setting overridden to x/n for the dynamic extent of the call, restoring the previous setting on exit. Task-scoped and thread-safe (see ScopedConfig); the global default is untouched.
Algorithm
- Widen an
Integerargument toInt, asset_compact_show!does. ABoolis passed unchanged. - Run
f()withCOMPACT_SHOWbound to that value throughwith_config.
Arguments
f: Zero-argument function to run under the override.x::Bool:falsedisables collapsing,trueenables it with the automatic budget.n::Integer: Fixed line budget, stored as anInt.
Returns
- The value that
f()returns.
Related
PortfolioOptimisers.compact_show_budget — Function
compact_show_budget(io::IO) -> Any
Resolve the line budget that triggers collapsing a nested struct rendered by @define_pretty_show.
The per-call :po_compact IO property takes precedence over the global COMPACT_SHOW setting; both accept false (disabled), true (automatic budget), or an Int (fixed budget). The automatic budget is max(8, displaysize(io)[1] - 4), so only subtrees that nearly fill or exceed the terminal collapse.
Algorithm
- Read the
:po_compactproperty ofio, givingv. - When
iosets no such property, collapsing applies only to height-limited output: returnnothingwhen:limitisfalse, and otherwise read the globalCOMPACT_SHOWsetting intov. - Return
nothingwhenvisfalse, because that value disables collapsing. - Return
Int(v)whenvis an integer that is not aBool, because that value is the fixed budget. - Otherwise
vistrue, so return the automatic budgetmax(8, displaysize(io)[1] - 4).
Arguments
io: Stream whose:po_compact,:limitand:displaysizeproperties the resolution reads.
Returns
nothingwhen collapsing is disabled.budget::Int(the maximum number of rendered lines a nested struct may occupy before collapsing) otherwise.
Related
PortfolioOptimisers.set_show_nothing_fields! — Function
set_show_nothing_fields!(x::Bool)
set_show_nothing_fields!(name::Symbol, x::Union{Nothing, Bool})Configure whether @define_pretty_show renders a field that holds nothing.
set_show_nothing_fields!(false): hide anothingfield, for every type that no per-name entry names. This is the shipped default.set_show_nothing_fields!(true): render anothingfield, for every type that no per-name entry names.set_show_nothing_fields!(:SimpleVariance, false): hide thenothingfields of every type namedSimpleVariance, whatever the global switch says.set_show_nothing_fields!(:SimpleVariance, true): render every declared field of every type namedSimpleVariance, including one that its ownshow_fieldsmethod hides.set_show_nothing_fields!(:SimpleVariance, nothing): remove the per-name entry, so the type follows the global switch and its ownshow_fieldsmethod again.
The per-name form takes a name and not a type, because the load-time preference channel is TOML, which carries no types. The name is the bare name of the type, so two types of one name in two modules share one entry. A name that matches no type is accepted and does nothing, because a type outside the package can render through @define_pretty_show too.
Sets the global default (atomically; see ScopedConfig). For a temporary, task-scoped override use with_show_nothing_fields.
Algorithm
- Read the current global default of
SHOW_NOTHING_FIELDSatomically. A scoped override is not read, so the call configures the global default alone. - Build the new
ShowNothingFields: the one-argument form keeps the per-name table and replaces the global switch, and the two-argument form keeps the global switch and copies the table with one entry set or removed. - Store it as the global default through
set_default!.
Arguments
x::Bool:falsehides anothingfield,truerenders it.name::Symbol: The bare name of a type.x::Union{Nothing, Bool}: In the per-name form, the entry to set, ornothingto remove the entry.
Returns
cfg::ShowNothingFields: The new global default.
Related
PortfolioOptimisers.with_show_nothing_fields — Function
with_show_nothing_fields(f, x::Bool)
with_show_nothing_fields(f, name::Symbol, x::Union{Nothing, Bool})Run f() with the SHOW_NOTHING_FIELDS setting overridden for the dynamic extent of the call, restoring the previous setting on exit. Task-scoped and thread-safe (see ScopedConfig); the global default is untouched. The part of the setting the call does not name inherits from the currently active value, so nested overrides compose.
Algorithm
- Read the currently active value of
SHOW_NOTHING_FIELDS, so that a nested override inherits from the enclosing one instead of from the global default. - Build the override as
set_show_nothing_fields!does: the one-argument form replaces the global switch and keeps the per-name table, and the two-argument form keeps the global switch and copies the table with one entry set or removed. - Run
f()withSHOW_NOTHING_FIELDSbound to that value throughwith_config.
Arguments
f: Zero-argument function to run under the override.x::Bool:falsehides anothingfield,truerenders it.name::Symbol: The bare name of a type.x::Union{Nothing, Bool}: In the per-name form, the entry to set, ornothingto remove the entry.
Returns
- The value that
f()returns.
Related
PortfolioOptimisers.set_string_distance! — Function
set_string_distance!(; dist::StringDistances.StringDistance, min_score::Real)Configure the global default fuzzy-suggestion settings read by did_you_mean. The store is atomic (see ScopedConfig); unspecified keywords keep their current default. For a temporary, task-scoped override use with_string_distance.
Algorithm
- Default each keyword the caller omits to the field of the current global default, read atomically. A scoped override is not read, so the call configures the global default alone.
- Build a
StringDistanceConfigfrom the two keywords, which is where the validation below runs. - Store it as the global default of
STRING_DISTANCEthroughset_default!.
Arguments
dist::StringDistances.StringDistance: Distance used to rank candidate names, for exampleStringDistances.Levenshtein(),StringDistances.DamerauLevenshtein()orStringDistances.JaroWinkler().min_score::Real: Minimum normalised similarity in(0, 1]that emits a suggestion. A value above1disables suggestions.
Validation
min_score > 0, enforced byStringDistanceConfig. A non-positive threshold admits every candidate with any nonzero similarity.
Returns
cfg::StringDistanceConfig: The new global default.
Related
PortfolioOptimisers.with_string_distance — Function
with_string_distance(f; dist::StringDistances.StringDistance = STRING_DISTANCE[].dist,
min_score::Real = STRING_DISTANCE[].min_score)Run f() with the fuzzy-suggestion settings read by did_you_mean overridden for the dynamic extent of the call, restoring the previous settings on exit. Task-scoped and thread-safe (see ScopedConfig); the global default is untouched. Unspecified keywords inherit from the currently active value, so nested overrides compose.
Useful around a meta-optimiser run to silence suggestions (min_score above 1) in its inner loops without affecting other concurrent work.
Algorithm
- Default each keyword the caller omits to the field of the currently active value, so that a nested override inherits from the enclosing one instead of from the global default.
- Build a
StringDistanceConfigfrom the two keywords, which is where the validation below runs. - Run
f()withSTRING_DISTANCEbound to that value throughwith_config.
Arguments
f: Zero-argument function to run under the override.dist::StringDistances.StringDistance: Distance used to rank candidate names.min_score::Real: Minimum normalised similarity in(0, 1]that emits a suggestion. A value above1disables suggestions.
Validation
min_score > 0, enforced byStringDistanceConfig.
Returns
- The value that
f()returns.
Related
PortfolioOptimisers.set_equation_limits! — Function
set_equation_limits!(; max_length::Integer, max_depth::Integer)Configure the global default equation-parser resource caps read at the string→AST trust boundary (see EQUATION_LIMITS).
Raise them for a genuinely large machine-generated constraint set, or lower them to tighten the boundary. Unspecified keywords keep their current default. The store is atomic (see ScopedConfig); for a temporary, task-scoped override use with_equation_limits.
Algorithm
- Default each keyword the caller omits to the field of the current global default, read atomically. A scoped override is not read, so the call configures the global default alone.
- Build an
EquationLimitsfrom the two keywords, which is where the validation below runs. - Store it as the global default of
EQUATION_LIMITSthroughset_default!.
Arguments
max_length::Integer: Maximum equation-string length passed toMeta.parse.max_depth::Integer: Maximum expression-tree depth accepted by theExprform ofparse_equation.
Validation
max_length > 0 && max_depth > 0, enforced byEquationLimits.
Returns
lims::EquationLimits: The new global default.
Related
PortfolioOptimisers.with_equation_limits — Function
with_equation_limits(f; max_length::Integer = EQUATION_LIMITS[].max_length,
max_depth::Integer = EQUATION_LIMITS[].max_depth)Run f() with the equation-parser resource caps (see EQUATION_LIMITS) overridden for the dynamic extent of the call, restoring the previous caps on exit. Task-scoped and thread-safe (see ScopedConfig); the global default is untouched. Unspecified keywords inherit from the currently active value, so nested overrides compose.
Useful to tighten the boundary around one batch of untrusted constraint strings, or to raise it for a single machine-generated constraint set, without affecting other concurrent work.
Algorithm
- Default each keyword the caller omits to the field of the currently active value, so that a nested override inherits from the enclosing one instead of from the global default.
- Build an
EquationLimitsfrom the two keywords, which is where the validation below runs. - Run
f()withEQUATION_LIMITSbound to that value throughwith_config.
Arguments
f: Zero-argument function to run under the override.max_length::Integer: Maximum equation-string length passed toMeta.parse.max_depth::Integer: Maximum expression-tree depth accepted by theExprform ofparse_equation.
Validation
max_length > 0 && max_depth > 0, enforced byEquationLimits.
Returns
- The value that
f()returns.
Related