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_LIMITSConstant
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

source
PortfolioOptimisers.COMPACT_SHOWConstant

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 of n.

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!).

source
PortfolioOptimisers.SHOW_NOTHING_FIELDSConstant
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

source
PortfolioOptimisers.STRING_DISTANCEConstant
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

source
PortfolioOptimisers.ScopedConfigType
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

source
PortfolioOptimisers.ResourceLimitsType
struct ResourceLimits

Global 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 by NormalUncertaintySet and ARCHUncertaintySet. The default is 1_000_000. Each draw stores an N × N covariance, so the backing array is N² · n_sim elements: at 20 assets the default cap already permits a 3.2 GB request, while the shipped n_sim is 3_000. Memory-bound.
  • max_n_subsets: Maximum resampled asset subsets (n_subsets) accepted by SubsetResampling and MultipleRandomised. The default is 100_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 is 2) yet well below a value that would wedge a session for days.
  • max_frontier: Maximum efficient-frontier sweep points accepted by the Frontier algorithm of MeanRisk and NearOptimalCentering. The default is 100_000. Like max_n_subsets it is compute-bound, because every point runs a full inner optimise_JuMP_model! solve, so it mirrors that ceiling; the shipped Frontier default is N = 20. It is enforced twice: Frontier's constructor caps the N of one bound, and assert_frontier_sweep_cap caps the product across every swept return term and every swept risk measure at Model Assembly, because the sweep is an Iterators.product and k bounds of N points cost N^k solves.
  • max_bins: Maximum histogram bins accepted by MutualInfoCovariance and VariationInfoDistance. The default is 10_000. The joint histogram is a bins × bins weights 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 by HopCount. The default is 100_000. Three readers sum A^i over i in 0:n, so the sink is linear in n at flops a power, and a large n wedges the session on compute rather than on memory. Like max_n_subsets it is compute-bound and mirrors that ceiling; the shipped default is n = 1. The cap is read in HopCount's constructor, which is also where resolve_separation sends a rule's answer, so one check covers the stated value and the computed one alike.
  • max_search_grid: Maximum search-grid candidates accepted by GridSearchCrossValidation and RandomisedSearchCrossValidation. The default is 100_000. Every candidate runs a full cross-validated fit, so this is compute-bound like max_n_subsets. The grid is an Iterators.product materialised by collect, so k parameters of N values cost N^k candidates: the cap is asserted on the product by assert_search_grid_cap where the grid is formed, because a per-parameter check can never see it.
  • max_ep_grid: Maximum grid points (K) accepted by GridEntropicValueatRiskView and GridRelativisticValueatRiskView. The default is 10_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 the T posterior probabilities, so the sink is a mixed-integer one: linear in K in memory at K · T coefficients, and a branch-and-bound tree over K binaries in compute. It therefore sits far below the compute ceilings that bound a plain solve, and far above the shipped K = 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) -> ResourceLimits

Keywords 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

source
PortfolioOptimisers.ShowNothingFieldsType
struct ShowNothingFields

Configuration 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 holds nothing prints for a type that no per-name entry names. The shipped default is false, so a nothing field is hidden.
  • by_type: Per-name overrides, keyed on the bare name of a type. A true entry prints every declared field of that type, and a false entry hides its nothing fields, whatever default holds and whatever the type's own show_fields method returns.

Constructors

ShowNothingFields(default::Bool, by_type::Dict{Symbol, Bool}) -> ShowNothingFieldsShowNothingFields(cfg::ShowNothingFields, name::Symbol,                  x::Union{Nothing, Bool}) -> ShowNothingFields

The second form copies cfg with one per-name entry changed: x sets the entry for name, and nothing removes it.

Related

source
PortfolioOptimisers.StringDistanceConfigType
struct StringDistanceConfig

Global 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 is StringDistances.Levenshtein().
  • min_score: Minimum normalised similarity a candidate must reach before it is suggested. The default is 0.7. A value toward 1 keeps only a near-exact match, and a value above 1 disables 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) -> StringDistanceConfig

Validation

  • min_score > 0. StringDistances.findnearest never suggests a candidate scoring exactly 0, but any threshold at or below 0 admits every candidate with some nonzero similarity, so 0 and a negative value behave identically. Both defeat the info-leak-safe boundary by naming a real asset for a near-miss probe.

Related

source
PortfolioOptimisers.EquationLimitsType
struct EquationLimits

Global 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 to Meta.parse. The default is 4096. 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 depth d needs at least d characters, so the length cap also bounds the AST depth of the string form.
  • max_depth: Maximum expression-tree depth accepted by the Expr form of parse_equation. The default is 256. That form receives a pre-built AST, which no length cap covers.

Constructors

EquationLimits(max_length::Integer, max_depth::Integer) -> EquationLimits

Validation

  • max_length > 0 && max_depth > 0.

Related

source
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

  1. Convert x to T, the element type of cfg, so that a failed conversion raises before anything is stored.
  2. Store the converted x into cfg.default in 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 type T of cfg.

Returns

  • x::T: The stored value.

Related

source
PortfolioOptimisers.with_configFunction
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

  1. Convert x to T, the element type of cfg.
  2. Bind cfg.scoped to the converted x and run f() inside that binding, so that the binding is restored when f returns and when f raises.

Arguments

  • f: Zero-argument function to run under the override.
  • cfg: Configuration holder to override.
  • x: Override value, converted to the element type T of cfg.

Returns

  • The value that f() returns.

Related

source
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

  1. 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.
  2. Build a ResourceLimits from the seven keywords, which is where the validation below runs.
  3. Store it as the global default of RESOURCE_LIMITS through set_default!.

Arguments

  • max_n_sim::Integer: Maximum n_sim accepted by the uncertainty-set estimators.
  • max_n_subsets::Integer: Maximum n_subsets accepted by the subset-resampling estimators.
  • max_frontier::Integer: Maximum N accepted by one Frontier, and maximum total sweep points across every swept bound.
  • max_bins::Integer: Maximum bins accepted by the mutual-information estimators.
  • max_hop_count::Integer: Maximum n accepted by HopCount, stated or resolved from a rule.
  • max_search_grid::Integer: Maximum total candidates in a search cross-validation grid.
  • max_ep_grid::Integer: Maximum K accepted by the grid formulations of the entropic and relativistic value-at-risk views.

Validation

Returns

  • lims::ResourceLimits: The new global default.

Related

source
PortfolioOptimisers.with_resource_limitsFunction
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

  1. 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.
  2. Build a ResourceLimits from the seven keywords, which is where the validation below runs.
  3. Run f() with RESOURCE_LIMITS bound to that value through with_config.

Arguments

  • f: Zero-argument function to run under the override.
  • max_n_sim::Integer: Maximum n_sim accepted by the uncertainty-set estimators.
  • max_n_subsets::Integer: Maximum n_subsets accepted by the subset-resampling estimators.
  • max_frontier::Integer: Maximum N accepted by one Frontier, and maximum total sweep points across every swept bound.
  • max_bins::Integer: Maximum bins accepted by the mutual-information estimators.
  • max_hop_count::Integer: Maximum n accepted by HopCount, stated or resolved from a rule.
  • max_search_grid::Integer: Maximum total candidates in a search cross-validation grid.
  • max_ep_grid::Integer: Maximum K accepted by the grid formulations of the entropic and relativistic value-at-risk views.

Validation

Returns

  • The value that f() returns.

Related

source
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 budget n.

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

  1. Widen an Integer argument to Int, so that the two methods store one of the two members of the stored union and never a third integer type. A Bool is stored unchanged.
  2. Store the value as the global default of COMPACT_SHOW through set_default!.

Arguments

  • x::Bool: false disables collapsing, true enables it with the automatic budget.
  • n::Integer: Fixed line budget, stored as an Int.

Returns

  • x::Union{Bool, Int}: The stored setting.

Related

source
PortfolioOptimisers.with_compact_showFunction
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

  1. Widen an Integer argument to Int, as set_compact_show! does. A Bool is passed unchanged.
  2. Run f() with COMPACT_SHOW bound to that value through with_config.

Arguments

  • f: Zero-argument function to run under the override.
  • x::Bool: false disables collapsing, true enables it with the automatic budget.
  • n::Integer: Fixed line budget, stored as an Int.

Returns

  • The value that f() returns.

Related

source
PortfolioOptimisers.compact_show_budgetFunction
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

  1. Read the :po_compact property of io, giving v.
  2. When io sets no such property, collapsing applies only to height-limited output: return nothing when :limit is false, and otherwise read the global COMPACT_SHOW setting into v.
  3. Return nothing when v is false, because that value disables collapsing.
  4. Return Int(v) when v is an integer that is not a Bool, because that value is the fixed budget.
  5. Otherwise v is true, so return the automatic budget max(8, displaysize(io)[1] - 4).

Arguments

  • io: Stream whose :po_compact, :limit and :displaysize properties the resolution reads.

Returns

  • nothing when collapsing is disabled.
  • budget::Int (the maximum number of rendered lines a nested struct may occupy before collapsing) otherwise.

Related

source
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 a nothing field, for every type that no per-name entry names. This is the shipped default.
  • set_show_nothing_fields!(true): render a nothing field, for every type that no per-name entry names.
  • set_show_nothing_fields!(:SimpleVariance, false): hide the nothing fields of every type named SimpleVariance, whatever the global switch says.
  • set_show_nothing_fields!(:SimpleVariance, true): render every declared field of every type named SimpleVariance, including one that its own show_fields method hides.
  • set_show_nothing_fields!(:SimpleVariance, nothing): remove the per-name entry, so the type follows the global switch and its own show_fields method 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

  1. Read the current global default of SHOW_NOTHING_FIELDS atomically. A scoped override is not read, so the call configures the global default alone.
  2. 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.
  3. Store it as the global default through set_default!.

Arguments

  • x::Bool: false hides a nothing field, true renders it.
  • name::Symbol: The bare name of a type.
  • x::Union{Nothing, Bool}: In the per-name form, the entry to set, or nothing to remove the entry.

Returns

  • cfg::ShowNothingFields: The new global default.

Related

source
PortfolioOptimisers.with_show_nothing_fieldsFunction
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

  1. 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.
  2. 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.
  3. Run f() with SHOW_NOTHING_FIELDS bound to that value through with_config.

Arguments

  • f: Zero-argument function to run under the override.
  • x::Bool: false hides a nothing field, true renders it.
  • name::Symbol: The bare name of a type.
  • x::Union{Nothing, Bool}: In the per-name form, the entry to set, or nothing to remove the entry.

Returns

  • The value that f() returns.

Related

source
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

  1. 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.
  2. Build a StringDistanceConfig from the two keywords, which is where the validation below runs.
  3. Store it as the global default of STRING_DISTANCE through set_default!.

Arguments

  • dist::StringDistances.StringDistance: Distance used to rank candidate names, for example StringDistances.Levenshtein(), StringDistances.DamerauLevenshtein() or StringDistances.JaroWinkler().
  • min_score::Real: Minimum normalised similarity in (0, 1] that emits a suggestion. A value above 1 disables suggestions.

Validation

  • min_score > 0, enforced by StringDistanceConfig. A non-positive threshold admits every candidate with any nonzero similarity.

Returns

  • cfg::StringDistanceConfig: The new global default.

Related

source
PortfolioOptimisers.with_string_distanceFunction
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

  1. 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.
  2. Build a StringDistanceConfig from the two keywords, which is where the validation below runs.
  3. Run f() with STRING_DISTANCE bound to that value through with_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 above 1 disables suggestions.

Validation

Returns

  • The value that f() returns.

Related

source
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

  1. 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.
  2. Build an EquationLimits from the two keywords, which is where the validation below runs.
  3. Store it as the global default of EQUATION_LIMITS through set_default!.

Arguments

  • max_length::Integer: Maximum equation-string length passed to Meta.parse.
  • max_depth::Integer: Maximum expression-tree depth accepted by the Expr form of parse_equation.

Validation

Returns

  • lims::EquationLimits: The new global default.

Related

source
PortfolioOptimisers.with_equation_limitsFunction
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

  1. 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.
  2. Build an EquationLimits from the two keywords, which is where the validation below runs.
  3. Run f() with EQUATION_LIMITS bound to that value through with_config.

Arguments

  • f: Zero-argument function to run under the override.
  • max_length::Integer: Maximum equation-string length passed to Meta.parse.
  • max_depth::Integer: Maximum expression-tree depth accepted by the Expr form of parse_equation.

Validation

Returns

  • The value that f() returns.

Related

source