Skip to content

Commit

Permalink
Merge pull request #201 from QE-Lab/enh/test-options-168
Browse files Browse the repository at this point in the history
updated option testing, closes #168
  • Loading branch information
imranashraf authored Oct 29, 2018
2 parents 79c0174 + 1602ae3 commit 027e4f3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ql/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace ql
{
app->reset();
EOUT("Un-known option:"<< e.what());
throw ql::exception("[x] Error parsing options. "+std::string(e.what())+" !",false);
throw ql::exception("Error parsing options. "+std::string(e.what())+" !",false);
}
app->reset();
}
Expand Down
83 changes: 74 additions & 9 deletions tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,85 @@

class Test_options(unittest.TestCase):

def test_ok(self):
ql.set_option('output_dir', output_dir)
def tearDown(self):
ql.set_option('log_level', 'LOG_NOTHING')
ql.set_option('optimize', 'no')
ql.set_option('scheduler', 'ALAP')
ql.set_option('scheduler_uniform', 'no')
ql.set_option('use_default_gates', 'yes')
ql.set_option('decompose_toffoli', 'no')


def test_set_all_options(self):
# try to set all legal values of options
ql.set_option('log_level', 'LOG_NOTHING')
ql.set_option('log_level', 'LOG_CRITICAL')
ql.set_option('log_level', 'LOG_ERROR')
ql.set_option('log_level', 'LOG_WARNING')
ql.set_option('log_level', 'LOG_INFO')
ql.set_option('log_level', 'LOG_DEBUG')

ql.set_option('output_dir', output_dir)

ql.set_option('optimize', 'yes')
ql.set_option('optimize', 'no')

ql.set_option('scheduler', 'ALAP')
ql.set_option('scheduler', 'ASAP')

ql.set_option('scheduler_uniform', 'yes')
ql.set_option('scheduler_uniform', 'no')

ql.set_option('use_default_gates', 'yes')
ql.set_option('use_default_gates', 'no')

ql.set_option('decompose_toffoli', 'no')
ql.set_option('decompose_toffoli', 'NC')
ql.set_option('decompose_toffoli', 'MA')


@unittest.skip
def test_nok(self):
# with self.assertRaises(RuntimeError) as cm:
try:
ql.set_option('optimize', 'Nope')
raise
except:
pass
# supress error printing first as the following will print errors
ql.set_option('log_level', 'LOG_NOTHING')

# illegal values for options should raise errors
with self.assertRaises(Exception) as cm:
ql.set_option('optimize', 'nope')

self.assertEqual(str(cm.exception), 'Error parsing options. The value nope is not an allowed value for --optimize !')


with self.assertRaises(Exception) as cm:
ql.set_option('scheduler', 'best')

self.assertEqual(str(cm.exception), 'Error parsing options. The value best is not an allowed value for --scheduler !')


def test_get_values(self):
# try to set a legal value and then test if it is indeed set
ql.set_option('log_level', 'LOG_INFO')
self.assertEqual(ql.get_option('log_level'), 'LOG_INFO')

ql.set_option('output_dir', output_dir)
self.assertEqual(ql.get_option('output_dir'), output_dir)

ql.set_option('optimize', 'yes')
self.assertEqual(ql.get_option('optimize'), 'yes')


ql.set_option('scheduler', 'ALAP')
self.assertEqual(ql.get_option('scheduler'), 'ALAP')

ql.set_option('scheduler_uniform', 'yes')
self.assertEqual(ql.get_option('scheduler_uniform'), 'yes')


ql.set_option('use_default_gates', 'yes')
self.assertEqual(ql.get_option('use_default_gates'), 'yes')

ql.set_option('decompose_toffoli', 'NC')
self.assertEqual(ql.get_option('decompose_toffoli'), 'NC')


def test_default_scheduler(self):
# tests if 'ALAP' is indeed the default scheduler policy
Expand Down

0 comments on commit 027e4f3

Please sign in to comment.