Skip to content

Commit

Permalink
Add functional tests for restarting from a seed mechanism
Browse files Browse the repository at this point in the history
The first test restarts the minimal example after ~20 species and includes filters. The second test restarts the super-minimal example after ~9 species and does not include filters.
  • Loading branch information
amarkpayne committed Dec 11, 2019
1 parent 240a690 commit d50cf62
Show file tree
Hide file tree
Showing 15 changed files with 5,485 additions and 1 deletion.
73 changes: 72 additions & 1 deletion rmgpy/rmg/mainTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
# #
###############################################################################

import logging
import os
import shutil
import unittest

from nose.plugins.attrib import attr

from rmgpy.rmg.main import RMG
from rmgpy.rmg.main import RMG, initialize_log
from rmgpy.rmg.main import RMG_Memory
from rmgpy import get_path
from rmgpy import settings
Expand Down Expand Up @@ -183,6 +184,76 @@ def test_make_cantera_input_file(self):
self.fail('The output Cantera file is not loadable in Cantera.')


@attr('functional')
class TestRestartWithFilters(unittest.TestCase):

@classmethod
def setUpClass(cls):
"""A function that is run ONCE before all unit tests in this class."""
cls.testDir = os.path.join(originalPath, 'rmg', 'test_data', 'restartTest')
cls.outputDir = os.path.join(cls.testDir, 'output_w_filters')
cls.databaseDirectory = settings['database.directory']

os.mkdir(cls.outputDir)
initialize_log(logging.INFO, os.path.join(cls.outputDir, 'RMG.log'))

cls.rmg = RMG(input_file=os.path.join(cls.testDir, 'restart_w_filters.py'),
output_directory=os.path.join(cls.outputDir))

def test_restart_with_filters(self):
"""
Test that the RMG restart job with filters included completed without problems
"""
cls.rmg.execute()
with open(os.path.join(self.outputDir, 'RMG.log'), 'r') as f:
self.assertIn('MODEL GENERATION COMPLETED', f.read())

@classmethod
def tearDownClass(cls):
"""A function that is run ONCE after all unit tests in this class."""
# Reset module level database
import rmgpy.data.rmg
rmgpy.data.rmg.database = None

# Remove output directory
shutil.rmtree(cls.outputDir)


@attr('functional')
class TestRestartNoFilters(unittest.TestCase):

@classmethod
def setUpClass(cls):
"""A function that is run ONCE before all unit tests in this class."""
cls.testDir = os.path.join(originalPath, 'rmg', 'test_data', 'restartTest')
cls.outputDir = os.path.join(cls.testDir, 'output_no_filters')
cls.databaseDirectory = settings['database.directory']

os.mkdir(cls.outputDir)
initialize_log(logging.INFO, os.path.join(cls.outputDir, 'RMG.log'))

cls.rmg = RMG(input_file=os.path.join(cls.testDir, 'restart_no_filters.py'),
output_directory=os.path.join(cls.outputDir))

def test_restart_no_filters(self):
"""
Test that the RMG restart job with no filters included completed without problems
"""
cls.rmg.execute()
with open(os.path.join(self.outputDir, 'RMG.log'), 'r') as f:
self.assertIn('MODEL GENERATION COMPLETED', f.read())

@classmethod
def tearDownClass(cls):
"""A function that is run ONCE after all unit tests in this class."""
# Reset module level database
import rmgpy.data.rmg
rmgpy.data.rmg.database = None

# Remove output directory
shutil.rmtree(cls.outputDir)


class TestCanteraOutput(unittest.TestCase):

def setUp(self):
Expand Down
57 changes: 57 additions & 0 deletions rmgpy/rmg/test_data/restartTest/restart_no_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
restartFromSeed(path='seed_no_filters')

# Data sources
database(
thermoLibraries = ['primaryThermoLibrary'],
reactionLibraries = [],
seedMechanisms = [],
kineticsDepositories = ['training'],
kineticsFamilies = ['H_Abstraction','Disproportionation','R_Recombination',
'Birad_recombination', 'Birad_R_Recombination'],
kineticsEstimator = 'rate rules',
)

# List of species
species(
label='H2',
reactive=True,
structure=SMILES("[H][H]"),
)
species(
label='O2',
reactive=True,
structure=SMILES("[O][O]"),
)

# Reaction systems
simpleReactor(
temperature=(1000,'K'),
pressure=(1.0,'bar'),
initialMoleFractions={
'H2':.67, 'O2':.33,
},
terminationConversion={
'H2': 0.9,
},
terminationTime=(1e6,'s'),
)

simulator(
atol=1e-16,
rtol=1e-8,
)

model(
toleranceKeepInEdge=0.0,
toleranceMoveToCore=0.001,
toleranceInterruptSimulation=0.001,
maximumEdgeSpecies=100000,
)

options(
units='si',
generateOutputHTML=True,
generatePlots=False,
saveEdgeSpecies=True,
saveSimulationProfiles=True,
)
52 changes: 52 additions & 0 deletions rmgpy/rmg/test_data/restartTest/restart_w_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
restartFromSeed(path='seed_w_filters')

# Data sources
database(
thermoLibraries = ['primaryThermoLibrary'],
reactionLibraries = [],
seedMechanisms = [],
kineticsDepositories = ['training'],
kineticsFamilies = 'default',
kineticsEstimator = 'rate rules',
)

# List of species
species(
label='ethane',
reactive=True,
structure=SMILES("CC"),
)

# Reaction systems
simpleReactor(
temperature=(1350,'K'),
pressure=(1.0,'bar'),
initialMoleFractions={
"ethane": 1.0,
},
terminationConversion={
'ethane': 0.9,
},
terminationTime=(1e6,'s'),
)

simulator(
atol=1e-16,
rtol=1e-8,
)

model(
toleranceKeepInEdge=0.0,
toleranceMoveToCore=0.1,
toleranceInterruptSimulation=0.1,
maximumEdgeSpecies=100000,
filterReactions=True,
)

options(
units='si',
generateOutputHTML=True,
generatePlots=False,
saveEdgeSpecies=True,
saveSimulationProfiles=True,
)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
- '1 Ar u0 p4 c0
'
- '1 He u0 p1 c0
'
- '1 Ne u0 p4 c0
'
- '1 N u0 p1 c0 {2,T}
2 N u0 p1 c0 {1,T}
'
- '1 H u0 p0 c0 {2,S}
2 H u0 p0 c0 {1,S}
'
- 'multiplicity 3
1 O u1 p2 c0 {2,S}
2 O u1 p2 c0 {1,S}
'
- 'multiplicity 2
1 H u1 p0 c0
'
- 'multiplicity 2
1 O u0 p2 c0 {2,S} {3,S}
2 O u1 p2 c0 {1,S}
3 H u0 p0 c0 {1,S}
'
- '1 O u0 p2 c0 {2,S} {3,S}
2 O u0 p2 c0 {1,S} {4,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {2,S}
'
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
H
multiplicity 2
1 H u1 p0 c0

H2
1 H u0 p0 c0 {2,S}
2 H u0 p0 c0 {1,S}

O2
multiplicity 3
1 O u1 p2 c0 {2,S}
2 O u1 p2 c0 {1,S}

[O]O
multiplicity 2
1 O u0 p2 c0 {2,S} {3,S}
2 O u1 p2 c0 {1,S}
3 H u0 p0 c0 {1,S}

OO
1 O u0 p2 c0 {2,S} {3,S}
2 O u0 p2 c0 {1,S} {4,S}
3 H u0 p0 c0 {1,S}
4 H u0 p0 c0 {2,S}

Loading

0 comments on commit d50cf62

Please sign in to comment.