Skip to content

Commit

Permalink
Fixed random seeds (#375)
Browse files Browse the repository at this point in the history
* fixed random seed

* 3.16.0 leftovers

* black

* moved random generator to setUp
  • Loading branch information
kanekosh committed Feb 2, 2022
1 parent a4f482c commit e2e3c84
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 79 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -69,14 +69,14 @@ Shamsheer S. Chauhan and Joaquim R. R. A. Martins, “Low-Fidelity Aerostructura

Version Information
-------------------
This version of OpenAeroStruct requires [OpenMDAO](https://github.com/OpenMDAO/openmdao) (versions 3.2.0 to 3.10.0) and Python3.
The latest version of OpenAeroStruct requires [OpenMDAO](https://github.com/OpenMDAO/openmdao) (versions 3.2.0 to 3.16.0) and Python3.
Python2 is no longer supported.
It also requires the folloing packages: `numpy, scipy, matplotlib`.
If you are looking to use the previous version of OpenAeroStruct which uses OpenMDAO 1.7.4, use OpenAeroStruct 1.0 from [here](https://github.com/mdolab/OpenAeroStruct/releases).

License
-------
Copyright 2018-2020 MDO Lab
Copyright 2018-2022 MDO Lab

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 2 additions & 4 deletions openaerostruct/aerodynamics/geometry.py
Expand Up @@ -3,9 +3,6 @@
import openmdao.api as om


np.random.seed(314)


class VLMGeometry(om.ExplicitComponent):
"""
Compute various geometric properties for VLM analysis.
Expand Down Expand Up @@ -49,7 +46,8 @@ def setup(self):
# All of these computations only need the deformed mesh
self.add_input("def_mesh", val=np.zeros((nx, ny, 3)), units="m")

self.add_output("b_pts", val=np.random.random((nx - 1, ny, 3)), units="m")
rng = np.random.default_rng(314)
self.add_output("b_pts", val=rng.random((nx - 1, ny, 3)), units="m")
self.add_output("widths", val=np.ones((ny - 1)), units="m")
self.add_output("cos_sweep", val=np.zeros((ny - 1)), units="m")
self.add_output("lengths", val=np.zeros((ny)), units="m")
Expand Down
3 changes: 2 additions & 1 deletion openaerostruct/aerodynamics/tests/test_convert_velocity.py
Expand Up @@ -26,7 +26,8 @@ def test_rotation_option_derivatives(self):
prob.model.add_subsystem("comp", comp)
prob.setup(force_alloc_complex=True)

prob["comp.rotational_velocities"] = np.random.random(prob["comp.rotational_velocities"].shape)
rng = np.random.default_rng(0)
prob["comp.rotational_velocities"] = rng.random(prob["comp.rotational_velocities"].shape)
prob["comp.beta"] = 15.0
prob.run_model()

Expand Down
18 changes: 10 additions & 8 deletions openaerostruct/aerodynamics/tests/test_geometry.py
Expand Up @@ -8,10 +8,12 @@
from openaerostruct.geometry.utils import generate_mesh
from openaerostruct.utils.testing import run_test, get_default_surfaces

np.random.seed(224)


class Test(unittest.TestCase):
def setUp(self):
# setup a random generator and fix the seed
self.rng = np.random.default_rng(1)

def test(self):
surfaces = get_default_surfaces()

Expand Down Expand Up @@ -42,7 +44,7 @@ def test_derivs_wetted(self):
# Generate the aerodynamic mesh based on the previous dictionary
mesh, twist_cp = generate_mesh(mesh_dict)

mesh[:, :, 2] = np.random.random(mesh[:, :, 2].shape)
mesh[:, :, 2] = self.rng.random(mesh[:, :, 2].shape)

# Create a dictionary with info and options about the aerodynamic
# lifting surface
Expand Down Expand Up @@ -92,11 +94,11 @@ def test_derivs_wetted(self):

prob.setup()

prob["geom.def_mesh"] = np.random.random(prob["geom.def_mesh"].shape)
prob["geom.def_mesh"] = mesh + self.rng.random(prob["geom.def_mesh"].shape) * 0.1

prob.run_model()

check = prob.check_partials(compact_print=True, step=1e-7)
check = prob.check_partials(compact_print=True, method="cs")
assert_check_partials(check, atol=5e-5, rtol=1e-5)

def test_derivs_projected(self):
Expand All @@ -112,7 +114,7 @@ def test_derivs_projected(self):
# Generate the aerodynamic mesh based on the previous dictionary
mesh, twist_cp = generate_mesh(mesh_dict)

mesh[:, :, 2] = np.random.random(mesh[:, :, 2].shape)
mesh[:, :, 2] = self.rng.random(mesh[:, :, 2].shape)

# Create a dictionary with info and options about the aerodynamic
# lifting surface
Expand Down Expand Up @@ -162,11 +164,11 @@ def test_derivs_projected(self):

prob.setup()

prob["geom.def_mesh"] = np.random.random(prob["geom.def_mesh"].shape)
prob["geom.def_mesh"] = mesh + self.rng.random(prob["geom.def_mesh"].shape) * 0.1

prob.run_model()

check = prob.check_partials(compact_print=True)
check = prob.check_partials(compact_print=True, method="cs")

assert_check_partials(check, atol=5e-5, rtol=1e-5)

Expand Down
3 changes: 2 additions & 1 deletion openaerostruct/aerodynamics/tests/test_lift_drag.py
Expand Up @@ -29,7 +29,8 @@ def test_derivs_with_sideslip(self):

prob["comp.alpha"] = 3.0
prob["comp.beta"] = 15.0
prob["comp.sec_forces"] = 10.0 * np.random.random(prob["comp.sec_forces"].shape)
rng = np.random.default_rng(0)
prob["comp.sec_forces"] = 10.0 * rng.random(prob["comp.sec_forces"].shape)

prob.run_model()

Expand Down
5 changes: 3 additions & 2 deletions openaerostruct/aerodynamics/tests/test_mesh_point_forces.py
Expand Up @@ -26,7 +26,8 @@ def test_derivatives(self):
# Generate the aerodynamic mesh based on the previous dictionary
mesh, twist_cp = generate_mesh(mesh_dict)

mesh[:, :, 2] = np.random.random(mesh[:, :, 2].shape)
rng = np.random.default_rng(0)
mesh[:, :, 2] = rng.random(mesh[:, :, 2].shape)

# Create a dictionary with info and options about the aerodynamic
# lifting surface
Expand All @@ -48,7 +49,7 @@ def test_derivatives(self):

prob.setup()

prob["comp.wing_sec_forces"] = np.random.random(prob["comp.wing_sec_forces"].shape)
prob["comp.wing_sec_forces"] = rng.random(prob["comp.wing_sec_forces"].shape)

prob.run_model()

Expand Down
56 changes: 30 additions & 26 deletions openaerostruct/aerodynamics/tests/test_pg_transform.py
Expand Up @@ -11,6 +11,10 @@


class Test(unittest.TestCase):
def setUp(self):
# setup a random generator and fix the seed
self.rng = np.random.default_rng(1)

def test_to_wind_derivs(self):
surfaces = get_default_surfaces()

Expand All @@ -20,15 +24,15 @@ def test_to_wind_derivs(self):
prob.model.add_subsystem("comp", comp)
prob.setup(force_alloc_complex=True)

prob["comp.alpha"] = np.random.random(prob["comp.alpha"].shape)
prob["comp.beta"] = np.random.random(prob["comp.beta"].shape)
prob["comp.coll_pts"] = np.random.random(prob["comp.coll_pts"].shape)
prob["comp.bound_vecs"] = np.random.random(prob["comp.bound_vecs"].shape)
prob["comp.rotational_velocities"] = np.random.random(prob["comp.rotational_velocities"].shape)
prob["comp.wing_def_mesh"] = np.random.random(prob["comp.wing_def_mesh"].shape)
prob["comp.tail_def_mesh"] = np.random.random(prob["comp.tail_def_mesh"].shape)
prob["comp.tail_normals"] = np.random.random(prob["comp.tail_normals"].shape)
prob["comp.wing_normals"] = np.random.random(prob["comp.wing_normals"].shape)
prob["comp.alpha"] = self.rng.random(prob["comp.alpha"].shape)
prob["comp.beta"] = self.rng.random(prob["comp.beta"].shape)
prob["comp.coll_pts"] = self.rng.random(prob["comp.coll_pts"].shape)
prob["comp.bound_vecs"] = self.rng.random(prob["comp.bound_vecs"].shape)
prob["comp.rotational_velocities"] = self.rng.random(prob["comp.rotational_velocities"].shape)
prob["comp.wing_def_mesh"] = self.rng.random(prob["comp.wing_def_mesh"].shape)
prob["comp.tail_def_mesh"] = self.rng.random(prob["comp.tail_def_mesh"].shape)
prob["comp.tail_normals"] = self.rng.random(prob["comp.tail_normals"].shape)
prob["comp.wing_normals"] = self.rng.random(prob["comp.wing_normals"].shape)

prob.run_model()

Expand All @@ -45,10 +49,10 @@ def test_from_wind_derivs(self):
prob.model.add_subsystem("comp", comp)
prob.setup(force_alloc_complex=True)

prob["comp.alpha"] = np.random.random(prob["comp.alpha"].shape)
prob["comp.beta"] = np.random.random(prob["comp.beta"].shape)
prob["comp.wing_sec_forces_w_frame"] = np.random.random(prob["comp.wing_sec_forces_w_frame"].shape)
prob["comp.tail_sec_forces_w_frame"] = np.random.random(prob["comp.tail_sec_forces_w_frame"].shape)
prob["comp.alpha"] = self.rng.random(prob["comp.alpha"].shape)
prob["comp.beta"] = self.rng.random(prob["comp.beta"].shape)
prob["comp.wing_sec_forces_w_frame"] = self.rng.random(prob["comp.wing_sec_forces_w_frame"].shape)
prob["comp.tail_sec_forces_w_frame"] = self.rng.random(prob["comp.tail_sec_forces_w_frame"].shape)

prob.run_model()

Expand All @@ -65,20 +69,20 @@ def test_scale_to_pg(self):
prob.model.add_subsystem("comp", comp)
prob.setup(force_alloc_complex=True)

prob["comp.Mach_number"] = np.random.random(prob["comp.Mach_number"].shape)
prob["comp.coll_pts_w_frame"] = np.random.random(prob["comp.coll_pts_w_frame"].shape)
prob["comp.bound_vecs_w_frame"] = np.random.random(prob["comp.bound_vecs_w_frame"].shape)
prob["comp.rotational_velocities_w_frame"] = np.random.random(prob["comp.rotational_velocities_w_frame"].shape)
prob["comp.wing_def_mesh_w_frame"] = np.random.random(prob["comp.wing_def_mesh_w_frame"].shape)
prob["comp.tail_def_mesh_w_frame"] = np.random.random(prob["comp.tail_def_mesh_w_frame"].shape)
prob["comp.tail_normals_w_frame"] = np.random.random(prob["comp.tail_normals_w_frame"].shape)
prob["comp.wing_normals_w_frame"] = np.random.random(prob["comp.wing_normals_w_frame"].shape)
prob["comp.Mach_number"] = self.rng.random(prob["comp.Mach_number"].shape)
prob["comp.coll_pts_w_frame"] = self.rng.random(prob["comp.coll_pts_w_frame"].shape)
prob["comp.bound_vecs_w_frame"] = self.rng.random(prob["comp.bound_vecs_w_frame"].shape)
prob["comp.rotational_velocities_w_frame"] = self.rng.random(prob["comp.rotational_velocities_w_frame"].shape)
prob["comp.wing_def_mesh_w_frame"] = self.rng.random(prob["comp.wing_def_mesh_w_frame"].shape)
prob["comp.tail_def_mesh_w_frame"] = self.rng.random(prob["comp.tail_def_mesh_w_frame"].shape)
prob["comp.tail_normals_w_frame"] = self.rng.random(prob["comp.tail_normals_w_frame"].shape)
prob["comp.wing_normals_w_frame"] = self.rng.random(prob["comp.wing_normals_w_frame"].shape)

prob.run_model()

check = prob.check_partials(compact_print=True, method="cs", step=1e-40)

assert_check_partials(check, atol=4e-5, rtol=4e-5)
assert_check_partials(check, atol=1e-5, rtol=1e-5)

def test_scale_from_pg(self):
surfaces = get_default_surfaces()
Expand All @@ -89,15 +93,15 @@ def test_scale_from_pg(self):
prob.model.add_subsystem("comp", comp)
prob.setup(force_alloc_complex=True)

prob["comp.Mach_number"] = np.random.random(prob["comp.Mach_number"].shape)
prob["comp.wing_sec_forces_pg"] = np.random.random(prob["comp.wing_sec_forces_pg"].shape)
prob["comp.tail_sec_forces_pg"] = np.random.random(prob["comp.tail_sec_forces_pg"].shape)
prob["comp.Mach_number"] = self.rng.random(prob["comp.Mach_number"].shape)
prob["comp.wing_sec_forces_pg"] = self.rng.random(prob["comp.wing_sec_forces_pg"].shape)
prob["comp.tail_sec_forces_pg"] = self.rng.random(prob["comp.tail_sec_forces_pg"].shape)

prob.run_model()

check = prob.check_partials(compact_print=True, method="cs", step=1e-40)

assert_check_partials(check, atol=2e-5, rtol=2e-5)
assert_check_partials(check, atol=1e-5, rtol=1e-5)


if __name__ == "__main__":
Expand Down
Expand Up @@ -28,7 +28,8 @@ def test_rotation_option_derivatives(self):

prob["comp.omega"] = np.array([0.3, 0.4, -0.1])
prob["comp.cg"] = np.array([0.1, 0.6, 0.4])
prob["comp.coll_pts"] = np.random.random(prob["comp.coll_pts"].shape)
rng = np.random.default_rng(0)
prob["comp.coll_pts"] = rng.random(prob["comp.coll_pts"].shape)
prob.run_model()

check = prob.check_partials(compact_print=True, method="cs", step=1e-40)
Expand Down
7 changes: 4 additions & 3 deletions openaerostruct/common/tests/test_reynolds_comp.py
Expand Up @@ -13,9 +13,10 @@ def test_reynolds_derivs(self):
prob.model.add_subsystem("comp", comp, promotes=["*"])
prob.setup(force_alloc_complex=True)

prob["rho"] = np.random.random()
prob["mu"] = np.random.random()
prob["v"] = np.random.random()
rng = np.random.default_rng(0)
prob["rho"] = rng.random()
prob["mu"] = rng.random()
prob["v"] = rng.random()
prob.run_model()

check = prob.check_partials(compact_print=True, method="cs", step=1e-40)
Expand Down

0 comments on commit e2e3c84

Please sign in to comment.