Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ Note: This is the main Changelog file for the Rust solver. The Changelog file fo
<!-- ---------------------
Unreleased
--------------------- -->
## [v0.9.2] - Unreleased

### Changed

- Update version of `rand`, `ndarray`, and `modcholesky` in `Cargo.toml`

<!-- ---------------------
v0.9.0
Expand Down Expand Up @@ -298,6 +302,7 @@ This is a breaking API change.
--------------------- -->

<!-- Releases -->
[v0.9.2]: https://github.com/alphaville/optimization-engine/compare/v0.9.1...v0.9.2
[v0.9.1]: https://github.com/alphaville/optimization-engine/compare/v0.9.0...v0.9.1
[v0.9.0]: https://github.com/alphaville/optimization-engine/compare/v0.8.1...v0.9.0
[v0.8.1]: https://github.com/alphaville/optimization-engine/compare/v0.8.0...v0.8.1
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ unit_test_utils = "0.1.3"
# instead, use:
icasadi_test = "0.0.2"
# Random number generators for unit tests:
rand = "0.8"
rand = "0.9"


# --------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions open-codegen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

Note: This is the Changelog file of `opengen` - the Python interface of OpEn

## [0.9.5] - Unreleased

### Changed

- Additional unit tests: increased coverage to 92%

## [0.9.4] - 2025-05-08


Expand Down
21 changes: 21 additions & 0 deletions open-codegen/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import opengen as og
import subprocess
import logging
import numpy as np


class RustBuildTestCase(unittest.TestCase):
Expand Down Expand Up @@ -527,6 +528,26 @@ def test_tcp_manager_remote_port_no_ip(self):
with self.assertRaises(Exception) as __context:
_remote_tcp_manager = og.tcp.OptimizerTcpManager(port=8888)

def test_set_y(self):
c = og.constraints.Ball2(radius=1)
y_calc = og.builder.SetYCalculator(c)
y = y_calc.obtain()

def test_squared_norm(self):
u = np.array([3, 4])
y = og.functions.norm2_squared(u)
self.assertAlmostEqual(25., y, places=12)

u = [3, 4]
y = og.functions.norm2_squared(u)
self.assertAlmostEqual(25., y, places=12)

u = cs.SX.sym("u", 2)
f = og.functions.norm2_squared(u)
fun = cs.Function('fun', [u], [f])
y = fun([3, 4])
self.assertAlmostEqual(25., y, places=12)


if __name__ == '__main__':
logging.getLogger('retry').setLevel(logging.ERROR)
Expand Down
30 changes: 30 additions & 0 deletions open-codegen/test/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ def test_cartesian_sx(self):
_sqd_sx = cartesian.distance_squared(u_sx)
u_mx = cs.SX.sym("u", 9, 1)
_sqd_mx = cartesian.distance_squared(u_mx)
self.assertEqual(2, cartesian.segment_dimension(0))
self.assertEqual(3, cartesian.segment_dimension(1))

def test_cartesian_segments_not_increasing(self):
no_constraints = og.constraints.NoConstraints()
Expand Down Expand Up @@ -343,6 +345,24 @@ def test_cartesian_segments_empty_args(self):
with self.assertRaises(ValueError) as __context:
og.constraints.CartesianProduct([], sets)

def test_cartesian_convex(self):
ball_inf = og.constraints.BallInf(None, 1)
ball_eucl = og.constraints.Ball2(None, 1)
cartesian = og.constraints.CartesianProduct(
[5, 10], [ball_inf, ball_eucl])
self.assertTrue(cartesian.is_convex())
self.assertTrue(cartesian.is_compact())

finite_set = og.constraints.FiniteSet([[1, 2, 3], [4, 5, 6]])
cartesian = og.constraints.CartesianProduct(
[5, 10, 13], [ball_inf, ball_eucl, finite_set])
self.assertFalse(cartesian.is_convex())

free = og.constraints.NoConstraints()
cartesian = og.constraints.CartesianProduct(
[5, 10, 11], [ball_inf, ball_eucl, free])
self.assertFalse(cartesian.is_compact())

# -----------------------------------------------------------------------
# Finite Set
# -----------------------------------------------------------------------
Expand Down Expand Up @@ -375,6 +395,10 @@ def test_finite_set_compact(self):
c = og.constraints.FiniteSet([[1, 2, 3], [4, 5, 6]])
self.assertTrue(c.is_compact())

def test_finite_set_dimension(self):
c = og.constraints.FiniteSet([[1, 2, 3], [4, 5, 6]])
self.assertEqual(3, c.dimension())

# -----------------------------------------------------------------------
# Halfspaces
# -----------------------------------------------------------------------
Expand Down Expand Up @@ -513,6 +537,12 @@ def test_sphere2_sq_distance_symbolic(self):
z = fun([1, 1, 0, 0])
self.assertAlmostEqual(0.835786437626905, z, places=12)

def test_sphere2_no_center(self):
sphere = og.constraints.Sphere2(radius=0.5)
u = [0, 0, 0, 0]
dist = sphere.distance_squared(u)
self.assertAlmostEqual(0.25, dist, places=12)


if __name__ == '__main__':
unittest.main()
Loading