Skip to content

Add user-facing Model predicates and restrict predicates to Model only#304

Merged
ocots merged 6 commits intomainfrom
empty-vs-set
Apr 20, 2026
Merged

Add user-facing Model predicates and restrict predicates to Model only#304
ocots merged 6 commits intomainfrom
empty-vs-set

Conversation

@ocots
Copy link
Copy Markdown
Member

@ocots ocots commented Apr 20, 2026

Add user-facing Model predicates and restrict predicates to Model only

This PR adds user-friendly predicate methods exclusively for Model instances and removes predicate methods for PreModel to enforce a clear separation between mutable construction and immutable problem definition.

Changes after commit bfc0198

New User-Facing Predicates (Model only)

  • has_variable(model) - alias for is_variable(model)
  • is_nonvariable(model) - opposite of is_variable(model)
  • has_control(model) - opposite of is_control_free(model)
  • has_abstract_definition(model) - checks if definition is non-empty
  • is_abstractly_defined(model) - alias for has_abstract_definition
  • is_nonautonomous(model) - opposite of is_autonomous(model)

Breaking Changes

Removed predicate methods for PreModel:

  • is_autonomous(ocp::PreModel) - removed
  • is_variable(ocp::PreModel) - removed
  • is_control_free(ocp::PreModel) - removed

These methods remain available for Model instances.

Internal Changes

  • Updated Display/pre_model.jl to use internal predicates (__is_variable_empty, __is_control_empty) and direct field access (ocp.autonomous)
  • Updated tests to use internal predicates for PreModel, public predicates for Model
  • Updated CHANGELOG.md and BREAKING.md documentation

Testing

All tests pass: 3617/3617

Migration Guide

# Before (PreModel access)
is_autonomous(pre)    # MethodError (removed)
is_variable(pre)      # MethodError (removed)
is_control_free(pre)  # MethodError (removed)

# After (use direct field access or internal predicates)
pre.autonomous                       # true/false
!__is_variable_empty(pre)            # true/false
__is_control_empty(pre)              # true/false

# New user-facing predicates (Model only)
has_variable(model)
has_control(model)
is_nonautonomous(model)
has_abstract_definition(model)

- Remove all __is_*_set(::Model) methods (trivial/unused)
- Remove __is_*_set(::PreModel) for optional fields (control, variable, definition)
- Add __is_*_empty(ocp::PreModel) overloads delegating to component
- Rewrite __is_empty(::PreModel) to use overloads for optional fields
- Remove __is_complete(::PreModel) (redundant with __is_consistent)
- Migrate all call sites from __is_*_set to !__is_*_empty for optional fields
- Update test assertions to reflect new predicate semantics
- Remove dead import __is_definition_set from Display.jl

This establishes clear semantic separation:
- __is_*_set: only for mandatory fields on PreModel
- __is_*_empty: only for optional fields (works on PreModel via overload)
ocots added 2 commits April 20, 2026 13:11
- Add has_variable, has_control, has_abstract_definition, is_abstractly_defined, is_nonautonomous, is_nonvariable for Model
- Remove is_autonomous, is_variable, is_control_free on PreModel
- Update Display call sites to use internal predicates
- Update tests accordingly
- Document removal of PreModel predicates (breaking change)
- Add new user-facing Model predicates documentation
- Update internal changes section
@ocots ocots added run breakage Used to trigger breakage tests. run ci Trigger CI run documentation Trigger documentation labels Apr 20, 2026
@control-toolbox control-toolbox deleted a comment from github-actions Bot Apr 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

Breakage test results
Date: 2026-04-20 15:18:11

Name Latest Stable
CTDirect compat: v0.9.15-beta compat: v0.9.15-beta
CTFlows compat: v0.9.15-beta compat: v0.9.15-beta
CTSolvers compat: v0.9.15-beta compat: v0.9.15-beta
OptimalControl compat: v0.9.15-beta compat: v0.9.15-beta

@ocots ocots changed the title Refactor predicates: strict separation of __is_*_set and __is_*_empty Add user-facing Model predicates and restrict predicates to Model only Apr 20, 2026
@ocots ocots merged commit 9555669 into main Apr 20, 2026
20 checks passed
@ocots ocots deleted the empty-vs-set branch April 20, 2026 15:00
@ocots ocots mentioned this pull request Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run breakage Used to trigger breakage tests. run ci Trigger CI run documentation Trigger documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant