Skip to content

Commit

Permalink
Fix tests due to solve method change (pccp). (#55)
Browse files Browse the repository at this point in the history
* Adding more advanced commands.

* First steps to fixing t_simulation.

* Hopefully tests run now.

* os.path.dirname.

* skip cvxopt again.

* Try AlmostEqual.
  • Loading branch information
1ozturkbe committed Apr 15, 2020
1 parent cfbf476 commit 4331d4f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/source/commands.rst
Expand Up @@ -106,6 +106,7 @@ which I have filled with some defaults:
number_of_time_average_solves, uncertainty_sets, nominal_solution, directly_uncertain_vars_subs, parallel,
nominal_number_of_constraints, nominal_solve_time]
Simulating a GPkit model is equivalent to optimizing the model over its remaining free variables (without
the 'fix' attribute). For Monte Carlo simulations, it is important to note that **the solution time is proportional
to the product of number of methods, uncertainty sets, gammas and samples**.
Expand All @@ -131,4 +132,3 @@ and other files in the ``simulate`` module
have simple demonstrations of saving/pickling.



26 changes: 13 additions & 13 deletions robust/testing/diffs/test_table.txt
@@ -1,14 +1,14 @@
L/D & 1.71e+01 & 1.66e+01 & 1.74e+01 & 1.77e+01
A & 1.00e+01 & 8.93e+00 & 9.21e+00 & 9.71e+00
Re & 4.64e+06 & 5.16e+06 & 5.21e+06 & 5.01e+06
S & 2.77e+01 & 4.43e+01 & 4.44e+01 & 4.14e+01
V & 5.71e+01 & 4.83e+01 & 4.86e+01 & 4.97e+01
t_s & 1.46e+01 & 1.73e+01 & 1.72e+01 & 1.68e+01
W_w & 2.24e+03 & 3.64e+03 & 3.69e+03 & 3.44e+03
W_{w_{strc}} & 5.79e+02 & 8.44e+02 & 8.85e+02 & 8.33e+02
W_{w_{surf}} & 1.66e+03 & 2.79e+03 & 2.80e+03 & 2.61e+03
W_{fuse} & 3.48e+02 & 3.81e+02 & 3.87e+02 & 3.92e+02
V_{f_{avail}} & 1.46e-01 & 1.86e-01 & 1.88e-01 & 1.81e-01
L/D & 1.7e+01 & 1.63e+01 & 1.71e+01 & 1.74e+01
A & 8.91e+00 & 7.54e+00 & 7.67e+00 & 8.27e+00
Re & 5.01e+06 & 5.78e+06 & 5.92e+06 & 5.60e+06
S & 2.82e+01 & 4.56e+01 & 4.58e+01 & 4.24e+01
V & 5.77e+01 & 4.91e+01 & 4.96e+01 & 5.07e+01
t_s & 1.44e+01 & 1.7e+01 & 1.68e+01 & 1.65e+01
W_w & 2.36e+03 & 3.89e+03 & 3.95e+03 & 3.67e+03
W_{w_{strc}} & 6.7e+02 & 1.01e+03 & 1.07e+03 & 9.88e+02
W_{w_{surf}} & 1.69e+03 & 2.87e+03 & 2.89e+03 & 2.68e+03
W_{fuse} & 3.5e+02 & 3.83e+02 & 3.93e+02 & 3.99e+02
V_{f_{avail}} & 1.5e-01 & 1.95e-01 & 1.96e-01 & 1.88e-01
V_{f_{fuse}} & 0.e+00 & 0.e+00 & 0.e+00 & 0.e+00
V_{f_{wing}} & 2.25e-01 & 5.07e-01 & 5.13e-01 & 4.49e-01
cost & 2.92e+03 & 3.56e+03 & 3.56e+03 & 3.46e+03
V_{f_{wing}} & 1.80e-01 & 3.84e-01 & 3.83e-01 & 3.29e-01
cost & 2.93e+03 & 3.6e+03 & 3.59e+03 & 3.48e+03
12 changes: 9 additions & 3 deletions robust/testing/t_simulation.py
Expand Up @@ -8,6 +8,7 @@
from robust.robust import RobustModel
from robust.simulations import simulate
from robust.testing.models import simple_ac
import pickle

class TestSimulation(unittest.TestCase):
solver = None
Expand Down Expand Up @@ -74,9 +75,14 @@ def test_table_diff(self):
esol = em.robustsolve(verbosity=0)

soltab = [sol, msol, bsol, esol]
diff_idx = ['sol', 'msol', 'bsol', 'esol']

origfilename = os.path.dirname(__file__) + '/' + 'diffs/test_table.txt'
filename = os.path.dirname(__file__) + '/' + 'diffs/test_table_diff.txt'
for i in range(len(soltab)):
soltab[i].save(filename=os.path.dirname(__file__) + '/diffs/' + diff_idx[i] + '.pkl')
# soltab[i].save('diffs/' + diff_idx[i] + '.pkl')

filename = os.path.dirname(__file__) + '/diffs/test_table_diff.txt'
origfilename = os.path.dirname(__file__) + '/diffs/test_table.txt'
f = open(filename, 'w+')

for i in ['L/D', 'A', 'Re', 'S', 'V', 't_s', 'W_w', 'W_{w_{strc}}', 'W_{w_{surf}}',
Expand All @@ -98,7 +104,7 @@ def test_table_diff(self):
f.write('\n')
f.close()

self.assertEqual(open(origfilename, 'r').readlines(), open(filename, 'r').readlines())
self.assertAlmostEqual(open(origfilename, 'r').readlines(), open(filename, 'r').readlines())

TESTS = [TestSimulation]

Expand Down
7 changes: 4 additions & 3 deletions setup.py
Expand Up @@ -8,7 +8,7 @@
"""

license = """MIT License
Copyright (c) 2018 Convex Engineering
Copyright (c) 2020 Convex Engineering
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
Expand All @@ -29,11 +29,12 @@
version='0.0.0',
description=description,
url='https://github.com/convexengineering/robust',
author='Ali Saab',
author_email='saab@mit.edu',
author='Ali Saab and Berk Ozturk',
author_email='bozturk@mit.edu',
license=license,
packages=["robust", "robust.data", "robust.feasibility_plots",
"robust.solar_model", "robust.synthetic_model", "robust.testing",
"robust.simulations"],
package_data={"robust.data":['*.txt'], "robust.solar_model":['*.txt']},
install_requires=['gpkit', 'gplibrary', 'numpy', 'matplotlib', 'scipy'])
s

0 comments on commit 4331d4f

Please sign in to comment.