From bf9813f8eb1f03a4fc9c0e6463346400e6c6cb2c Mon Sep 17 00:00:00 2001
From: Pantelis Sopasakis
Date: Mon, 25 Mar 2024 03:25:17 +0000
Subject: [PATCH 1/4] more testing; reached 92% coverage
---
open-codegen/test/test.py | 21 +++++++++++++++++++
open-codegen/test/test_constraints.py | 30 +++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/open-codegen/test/test.py b/open-codegen/test/test.py
index 2b55ad89..21a7d13f 100644
--- a/open-codegen/test/test.py
+++ b/open-codegen/test/test.py
@@ -4,6 +4,7 @@
import opengen as og
import subprocess
import logging
+import numpy as np
class RustBuildTestCase(unittest.TestCase):
@@ -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)
diff --git a/open-codegen/test/test_constraints.py b/open-codegen/test/test_constraints.py
index 4421cbd8..8cff3f6c 100644
--- a/open-codegen/test/test_constraints.py
+++ b/open-codegen/test/test_constraints.py
@@ -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()
@@ -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
# -----------------------------------------------------------------------
@@ -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
# -----------------------------------------------------------------------
@@ -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()
From d8d06cd9ff943b704a943740e6c1e6762ef254b0 Mon Sep 17 00:00:00 2001
From: Pantelis Sopasakis
Date: Thu, 22 May 2025 16:41:32 +0100
Subject: [PATCH 2/4] update opengen changelog; bump rand version to 0.9
---
Cargo.toml | 2 +-
open-codegen/CHANGELOG.md | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/Cargo.toml b/Cargo.toml
index 00393acb..b967529b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"
# --------------------------------------------------------------------------
diff --git a/open-codegen/CHANGELOG.md b/open-codegen/CHANGELOG.md
index ce7f82d7..b9e7ccde 100644
--- a/open-codegen/CHANGELOG.md
+++ b/open-codegen/CHANGELOG.md
@@ -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
From 0bb8dc5f299504c606741b065131c50aead07b40 Mon Sep 17 00:00:00 2001
From: Pantelis Sopasakis
Date: Thu, 22 May 2025 16:43:33 +0100
Subject: [PATCH 3/4] update changelog
---
CHANGELOG.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f36ba7a5..85f34cae 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,7 +11,11 @@ Note: This is the main Changelog file for the Rust solver. The Changelog file fo
+## [v0.9.2] - Unreleased
+### Changed
+
+- Update version of `rand`, `ndarray`, and `modcholesky` in `Cargo.toml`
+[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