Skip to content

add cartpole example#10

Closed
Transurgeon wants to merge 1 commit into
masterfrom
adding-cartpole-example
Closed

add cartpole example#10
Transurgeon wants to merge 1 commit into
masterfrom
adding-cartpole-example

Conversation

@Transurgeon

Copy link
Copy Markdown
Member

Description

Please include a short summary of the change.
suggested by kevin tracy.
Issue link (if applicable):

Type of change

  • New feature (backwards compatible)
  • New feature (breaking API changes)
  • Bug fix
  • Other (Documentation, CI, ...)

Contribution checklist

  • Add our license to new files.
  • Check that your code adheres to our coding style.
  • Write unittests.
  • Run the unittests and check that they’re passing.
  • Run the benchmarks to make sure your change doesn’t introduce a regression.

Transurgeon added a commit that referenced this pull request Mar 27, 2026
Enable cp.Parameter objects to be treated as updatable nodes in the C
expression DAG instead of being baked in as constants. On re-solve with
new parameter values, the cached DAG and sparsity structures are reused
via problem._nlp_cache, analogous to DPP for conic programs.

Requires SparseDiffPy PR #10 for make_parameter, problem_register_params,
and problem_update_params bindings. Tests skip gracefully until installed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Transurgeon added a commit that referenced this pull request Apr 11, 2026
* Add parameter support to DNLP diff engine

Enable cp.Parameter objects to be treated as updatable nodes in the C
expression DAG instead of being baked in as constants. On re-solve with
new parameter values, the cached DAG and sparsity structures are reused
via problem._nlp_cache, analogous to DPP for conic programs.

Requires SparseDiffPy PR #10 for make_parameter, problem_register_params,
and problem_update_params bindings. Tests skip gracefully until installed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Remove unused converters and simplify NLP parameter cache

Remove diag_mat, upper_tri, vstack, and kron converters and their tests.

Simplify solve_nlp parameter caching to mirror the best_of pattern:
always re-run the full reduction chain, cache only the solver_cache
(Oracles) on problem._nlp_cache between solve() calls.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Simplify parameter plumbing: replace InverseData with param_id_map

Replace build_theta(params, inverse_data) with simple concatenation.
Add build_param_id_map() helper. Replace inverse_data parameter with
param_id_map dict throughout converters, C_problem, and Oracles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Remove test_nlp_parameters.py for now

Will revisit testing after SparseDiffPy parameter bindings are available.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Clean up converters: add ConvertContext, uniform converter signatures

Replace scattered var_dict/n_vars/param_id_map threading with a single
ConvertContext class built from InverseData. All atom converters now
have uniform (expr, children, ctx) signature.

Remove _is_parametric, _PARAMETRIC_CONVERTERS, build_param_id_map,
build_variable_dict, convert_expressions. C_problem creates its own
InverseData internally.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Keep original (expr, children) converter signatures

Move matmul/multiply parameter handling to ConvertContext methods.
All other converters keep their original (expr, children) signature
untouched. convert_expr dispatches matmul/multiply specially via ctx.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Restore original converter signatures, minimal parameter changes

Keep all atom converters with their original (expr, children) signatures.
Only matmul and multiply are handled via ConvertContext methods.
ATOM_CONVERTERS dict entries preserved exactly as original.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Move parameter update into solve_via_data, use _solver_cache['NLP']

Move update_params call into ipopt solve_via_data (where oracles are
reused). Remove _get_solver_cache helper and _nlp_cache dict. Store
solver_cache in the existing problem._solver_cache['NLP'] — zero
changes to problem.py.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Clean up parameter update: inline into Oracles, add to all NLP solvers

Move theta construction into Oracles.update_params(problem). Remove
build_theta from converters. Add update_params call to all four NLP
solvers (IPOPT, Knitro, Uno, COPT) on oracle reuse path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* adds tests for parameters

* Add parameter tests, initial value init, update_params in all solvers

- Add test_nlp_parameters.py with 3 tests (scalar, vector, matrix)
- Initialize parameter values after registration in C_problem
- Add oracles.update_params() call to all NLP solvers on cache reuse
- Use problem._solver_cache['NLP'] for oracle caching
- Restore original docstrings in c_problem.py

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Always pass param_node to matmul helpers (required by new SparseDiffPy)

The parameter-bindings branch of SparseDiffPy always requires
param_or_none as the first arg to matmul functions. Pass it
unconditionally (None for non-parametric).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Replace ConvertContext with flat functions for converter state

Keep master's convert_expr(expr, var_dict, n_vars) pattern, adding
param_dict as an optional arg. Matmul/multiply stay as standalone
functions rather than class methods.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Update CLAUDE.md with DNLP architecture documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Split converters.py into helpers.py, registry.py, and converters.py

- helpers.py: shared utilities, matmul helpers, var/param dict builders
- registry.py: atom converter functions and ATOM_CONVERTERS dict
- converters.py: convert_expr entry point and param-aware matmul/multiply

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Fix lint and remove section comment banners

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* chnages from code review with dance

* add test for right elementwise multiply, which forces an argument order swap

* minor edits to parameters

* adding test for parametrized least-squares vs. clarabel

* make three more legit parameter tests

* tests

* fix tests so they test the right thing

* added comment

* add comments

* add comment

* small tweaks to pass parameter values and new tests

* add derivative checker to parameter tests

* two more tests

* trigger ci rerun

* update pinned sparsediffpy version to 0.2.0

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: dance858 <danielcederberg1@gmail.com>
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.

1 participant