Skip to content

Commit

Permalink
Update test results
Browse files Browse the repository at this point in the history
  • Loading branch information
hwpang committed Jan 30, 2024
1 parent 29491fd commit 8482786
Showing 1 changed file with 49 additions and 48 deletions.
97 changes: 49 additions & 48 deletions test/arkane/encorr/isodesmicTest.py
Expand Up @@ -162,45 +162,60 @@ def test_enumerating_constraints(self):
Test that a SpeciesConstraints object can properly enumerate the constraints of a given ErrorCancelingSpecies
"""
spcs_consts = SpeciesConstraints(self.benzene, [])
assert set(spcs_consts.constraint_map.keys()) == {"C", "H", "C=C", "C-C", "C-H", "6_ring"}

# Now that we have confirmed that the correct keys are present, overwrite the constraint map to set the order
spcs_consts.constraint_map = {
"H": 0,
"C": 1,
"C=C": 2,
"C-C": 3,
"C-H": 4,
"6_ring": 5,
}
benzene_features = spcs_consts._get_all_constraints(self.benzene)
benzene_constraint_list = [feat.__repr__() for feat in benzene_features]
assert set(benzene_constraint_list) == {"C=C", "C-C", "C-H", "6_ring"}

target_constraints, _ = spcs_consts._enumerate_constraints([benzene_features])
benzene_constraints = target_constraints

assert np.array_equal(
spcs_consts._enumerate_constraints(self.propene),
np.array([6, 3, 1, 1, 6, 0]),
benzene_constraints,
np.array([1, 3, 6, 3]),
)

spcs_consts.all_reference_species = [self.propene]
propene_features = spcs_consts._get_all_constraints(self.propene)
_, reference_constraints = spcs_consts._enumerate_constraints([benzene_features, propene_features])
propene_constraints = reference_constraints[0]
assert np.array_equal(
spcs_consts._enumerate_constraints(self.butane),
np.array([10, 4, 0, 3, 10, 0]),
propene_constraints,
np.array([0, 1, 6, 1]),
)

spcs_consts.all_reference_species = [self.butane]
butane_features = spcs_consts._get_all_constraints(self.butane)
_, reference_constraints = spcs_consts._enumerate_constraints([benzene_features, butane_features])
butane_constraints = reference_constraints[0]
assert np.array_equal(
spcs_consts._enumerate_constraints(self.benzene),
np.array([6, 6, 3, 3, 6, 1]),
butane_constraints,
np.array([0, 3, 10, 0]),
)

# Caffeine and ethyne should return None since they have features not found in benzene
assert spcs_consts._enumerate_constraints(self.caffeine) is None
assert spcs_consts._enumerate_constraints(self.ethyne) is None
# Caffeine and ethyne should return empty list since they have features not found in benzene
spcs_consts.all_reference_species = [self.caffeine]
caffeine_features = spcs_consts._get_all_constraints(self.caffeine)
_, reference_constraints = spcs_consts._enumerate_constraints([benzene_features, caffeine_features])
assert len(reference_constraints) == 0

spcs_consts.all_reference_species = [self.ethyne]
ethyne_features = spcs_consts._get_all_constraints(self.ethyne)
_, reference_constraints = spcs_consts._enumerate_constraints([benzene_features, ethyne_features])
assert len(reference_constraints) == 0

def test_calculating_constraints(self):
"""
Test that a SpeciesConstraints object can properly return the target constraint vector and the constraint matrix
"""
spcs_consts = SpeciesConstraints(self.caffeine, [self.propene, self.butane, self.benzene, self.ethyne])
assert set(spcs_consts.constraint_map.keys()) == {
"H",
"C",
"O",
"N",
caffeine_features = spcs_consts._get_all_constraints(self.caffeine)
propene_features = spcs_consts._get_all_constraints(self.propene)
butane_features = spcs_consts._get_all_constraints(self.butane)
benzene_features = spcs_consts._get_all_constraints(self.benzene)
ethyne_features = spcs_consts._get_all_constraints(self.ethyne)

caffeine_feature_list = [feat.__repr__() for feat in caffeine_features]
assert set(caffeine_feature_list) == {
"C=O",
"C-N",
"C-H",
Expand All @@ -211,36 +226,20 @@ def test_calculating_constraints(self):
"6_ring",
}

# Now that we have confirmed that the correct keys are present, overwrite the constraint map to set the order
spcs_consts.constraint_map = {
"H": 0,
"C": 1,
"O": 2,
"N": 3,
"C=O": 4,
"C-N": 5,
"C-H": 6,
"C=C": 7,
"C=N": 8,
"C-C": 9,
"5_ring": 10,
"6_ring": 11,
}

target_consts, consts_matrix = spcs_consts.calculate_constraints()

# First, test that ethyne is not included in the reference set
assert spcs_consts.reference_species == [self.propene, self.butane, self.benzene]

# Then, test the output of the calculation
assert np.array_equal(target_consts, np.array([10, 8, 2, 4, 2, 10, 10, 1, 1, 1, 1, 1]))
assert np.array_equal(target_consts, np.array([ 1, 1, 1, 10, 10, 1, 1, 2, 0, 8, 10, 4, 2]))
assert np.array_equal(
consts_matrix,
np.array(
[
[6, 3, 0, 0, 0, 0, 6, 1, 0, 1, 0, 0],
[10, 4, 0, 0, 0, 0, 10, 0, 0, 3, 0, 0],
[6, 6, 0, 0, 0, 0, 6, 3, 0, 3, 0, 1],
[ 0, 0, 1, 6, 0, 1, 0, 0, 0, 3, 6, 0, 0],
[ 0, 0, 3, 10, 0, 0, 0, 0, 0, 4, 10, 0, 0],
[ 0, 1, 3, 6, 0, 3, 0, 0, 0, 6, 6, 0, 0],
]
),
)
Expand Down Expand Up @@ -276,6 +275,8 @@ def test_creating_error_canceling_schemes(self):
scheme = ErrorCancelingScheme(
self.propene,
[self.butane, self.benzene, self.caffeine, self.ethyne],
"rc2",
True,
True,
True,
)
Expand Down Expand Up @@ -326,7 +327,7 @@ def test_multiple_error_canceling_reactions(self):
)

reaction_list = scheme.multiple_error_canceling_reaction_search(n_reactions_max=20)
assert len(reaction_list) == 20
assert len(reaction_list) == 6
reaction_string = reaction_list.__repr__()
# Consider both permutations of the products in the reaction string
rxn_str1 = "<ErrorCancelingReaction 1*C=CC + 1*CCCC <=> 1*CCC + 1*C=CCC >"
Expand Down Expand Up @@ -359,9 +360,9 @@ def test_calculate_target_enthalpy(self):
)

target_thermo, rxn_list = scheme.calculate_target_enthalpy(n_reactions_max=3, milp_software=["lpsolve"])
assert target_thermo.value_si == 115000.0
assert target_thermo.value_si == 110000.0
assert isinstance(rxn_list[0], ErrorCancelingReaction)

if self.pyo is not None:
target_thermo, _ = scheme.calculate_target_enthalpy(n_reactions_max=3, milp_software=["pyomo"])
assert target_thermo.value_si == 115000.0
assert target_thermo.value_si == 110000.0

0 comments on commit 8482786

Please sign in to comment.