Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart attribute error #1847

Merged
merged 3 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions rmgpy/rmg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1558,11 +1558,11 @@ def initialize_reaction_threshold_and_react_flags(self):

# Load in the restart filter tensors
with h5py.File(self.filters_path, 'r') as f:
try:
unimolecular_threshold_restart = f.get('unimolecular_threshold').value
bimolecular_threshold_restart = f.get('bimolecular_threshold').value
if 'unimolecular_threshold' in f.keys():
unimolecular_threshold_restart = f.get('unimolecular_threshold')[()]
bimolecular_threshold_restart = f.get('bimolecular_threshold')[()]
if self.trimolecular:
trimolecular_threshold_restart = f.get('trimolecular_threshold').value
trimolecular_threshold_restart = f.get('trimolecular_threshold')[()]

# Expand Thresholds to match number of species in the current model.
# Note that we are about to reorder the core species to match the order in the restart seed
Expand All @@ -1581,7 +1581,7 @@ def initialize_reaction_threshold_and_react_flags(self):

filters_found = True

except KeyError: # If we can't find the filters then this is because filtering was not used
else: # If we can't find the filters then this is because filtering was not used
logging.warning('No filters were found in file {0}. This is to be expected if the restart '
'files specified are from an RMG job without reaction filtering. Therefore, '
'RMG will assume that all of the core species from the restart core seed have '
Expand Down
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
"""
self.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
"""
self.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