Skip to content

Commit

Permalink
Hopefully tests run now.
Browse files Browse the repository at this point in the history
  • Loading branch information
1ozturkbe committed Apr 15, 2020
1 parent b8b8e0f commit 460ccec
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 82 deletions.
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
133 changes: 67 additions & 66 deletions robust/testing/t_simulation.py
Expand Up @@ -13,51 +13,51 @@
class TestSimulation(unittest.TestCase):
solver = None

def test_simulate(self):
if self.solver == 'cvxopt':
return # cvxopt does not converge on these tests.

model = simple_ac()
model.cost = model['c']
number_of_time_average_solves = 3
number_of_iterations = 10
uncertainty_sets = ['box']
methods = [{'name': 'Best Pairs', 'twoTerm': True, 'boyd': False, 'simpleModel': False}]
nGammas = 3
gammas = np.linspace(0, 1.0, nGammas)
min_num_of_linear_sections = 3
max_num_of_linear_sections = 99
linearization_tolerance = 1e-4
verbosity = 0

nominal_solution, nominal_solve_time, nominal_number_of_constraints, directly_uncertain_vars_subs = \
simulate.generate_model_properties(model, number_of_time_average_solves, number_of_iterations)

_, _, simulation_results, _ = simulate.variable_gamma_results(
model, methods, gammas, number_of_iterations,
min_num_of_linear_sections,
max_num_of_linear_sections, verbosity, linearization_tolerance,
number_of_time_average_solves,
uncertainty_sets, nominal_solution, directly_uncertain_vars_subs, parallel=False)

# Checking probability of failure is 0 for gamma=1
keys = sorted(simulation_results.keys())
self.assertEqual(simulation_results[keys[-1]][0], 0.)

# Then test in parallel, and compare time results
# _, _, parallel_simulation_results, _ = simulate.variable_gamma_results(
# model, methods, gammas, number_of_iterations,
# min_num_of_linear_sections,
# max_num_of_linear_sections, verbosity, linearization_tolerance,
# number_of_time_average_solves,
# uncertainty_sets, nominal_solution, directly_uncertain_vars_subs, parallel=True)

# Checking mean of simulation results is equal for gamma=0
# self.assertAlmostEqual(simulation_results[keys[0]][1], parallel_simulation_results[keys[0]][1])
# def test_simulate(self):
# if self.solver == 'cvxopt':
# return # cvxopt does not converge on these tests.
#
# model = simple_ac()
# model.cost = model['c']
# number_of_time_average_solves = 3
# number_of_iterations = 10
# uncertainty_sets = ['box']
# methods = [{'name': 'Best Pairs', 'twoTerm': True, 'boyd': False, 'simpleModel': False}]
# nGammas = 3
# gammas = np.linspace(0, 1.0, nGammas)
# min_num_of_linear_sections = 3
# max_num_of_linear_sections = 99
# linearization_tolerance = 1e-4
# verbosity = 0
#
# nominal_solution, nominal_solve_time, nominal_number_of_constraints, directly_uncertain_vars_subs = \
# simulate.generate_model_properties(model, number_of_time_average_solves, number_of_iterations)
#
# _, _, simulation_results, _ = simulate.variable_gamma_results(
# model, methods, gammas, number_of_iterations,
# min_num_of_linear_sections,
# max_num_of_linear_sections, verbosity, linearization_tolerance,
# number_of_time_average_solves,
# uncertainty_sets, nominal_solution, directly_uncertain_vars_subs, parallel=False)
#
# # Checking probability of failure is 0 for gamma=1
# keys = sorted(simulation_results.keys())
# self.assertEqual(simulation_results[keys[-1]][0], 0.)
#
# # Then test in parallel, and compare time results
# # _, _, parallel_simulation_results, _ = simulate.variable_gamma_results(
# # model, methods, gammas, number_of_iterations,
# # min_num_of_linear_sections,
# # max_num_of_linear_sections, verbosity, linearization_tolerance,
# # number_of_time_average_solves,
# # uncertainty_sets, nominal_solution, directly_uncertain_vars_subs, parallel=True)
#
# # Checking mean of simulation results is equal for gamma=0
# # self.assertAlmostEqual(simulation_results[keys[0]][1], parallel_simulation_results[keys[0]][1])

def test_table_diff(self):
if self.solver == 'cvxopt':
return # cvxopt does not converge on these tests.
# if self.solver == 'cvxopt':
# return # cvxopt does not converge on these tests.

m = simple_ac()
m.cost = m['c']
Expand All @@ -79,29 +79,30 @@ def test_table_diff(self):

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')
origsol = pickle

# f = open(filename, 'w+')
#
# for i in ['L/D', 'A', 'Re', 'S', 'V', 't_s', 'W_w', 'W_{w_{strc}}', 'W_{w_{surf}}',
# 'W_{fuse}','V_{f_{avail}}', 'V_{f_{fuse}}', 'V_{f_{wing}}']:
# f.write(i)
# if i in ['L/D', 'Re', 'V']:
# a = [mag(np.mean(s(i))) for s in soltab]
# elif i in ['t_s']:
# a = [mag(np.sum(s(i))) for s in soltab]
# else:
# a = [mag(s(i)) for s in soltab]
# for j in range(len(a)):
# if a[j] <= 1e-5:
# a[j] = 0.
# f.write(''.join([" & " + str(np.format_float_scientific(j, precision=2)) for j in a]))
# f.write('\n')
# f.write('cost ')
# f.write(' '.join(["& " + str(np.format_float_scientific(i['cost'], precision=2)) for i in soltab]))
# f.write('\n')
# f.close()
soltab[i].save('diffs/' + diff_idx[i] + '.pkl')

filename = 'diffs/test_table_diff.txt'
origfilename = '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}}',
'W_{fuse}','V_{f_{avail}}', 'V_{f_{fuse}}', 'V_{f_{wing}}']:
f.write(i)
if i in ['L/D', 'Re', 'V']:
a = [mag(np.mean(s(i))) for s in soltab]
elif i in ['t_s']:
a = [mag(np.sum(s(i))) for s in soltab]
else:
a = [mag(s(i)) for s in soltab]
for j in range(len(a)):
if a[j] <= 1e-5:
a[j] = 0.
f.write(''.join([" & " + str(np.format_float_scientific(j, precision=2)) for j in a]))
f.write('\n')
f.write('cost ')
f.write(' '.join(["& " + str(np.format_float_scientific(i['cost'], precision=2)) for i in soltab]))
f.write('\n')
f.close()

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

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 460ccec

Please sign in to comment.