matrices: broadcast key combinatorially applies to all nodes in matrix

This commit is contained in:
Gregory Becker 2023-02-23 15:40:34 -08:00
parent 6b27aebeb4
commit 7014eb3236
3 changed files with 35 additions and 4 deletions

View File

@ -30,6 +30,10 @@
"type": "array", "type": "array",
"items": {"type": "array", "items": {"type": "string"}}, "items": {"type": "array", "items": {"type": "string"}},
}, },
"broadcast": {
"type": "array",
"items": {"type": "array", "items": {"type": "string"}},
},
"exclude": {"type": "array", "items": {"type": "string"}}, "exclude": {"type": "array", "items": {"type": "string"}},
}, },
}, },

View File

@ -186,9 +186,13 @@ def _expand_matrix_constraints(matrix_config):
new_row.append([r]) new_row.append([r])
expanded_rows.append(new_row) expanded_rows.append(new_row)
# TODO someday: allow matrices inside `broadcast`
broadcast_rows = matrix_config.get("broadcast", [])
excludes = matrix_config.get("exclude", []) # only compute once excludes = matrix_config.get("exclude", []) # only compute once
sigil = matrix_config.get("sigil", "") sigil = matrix_config.get("sigil", "")
broadcast_constraints = list(itertools.product(*broadcast_rows))
results = [] results = []
for combo in itertools.product(*expanded_rows): for combo in itertools.product(*expanded_rows):
# Construct a combined spec to test against excludes # Construct a combined spec to test against excludes
@ -212,15 +216,29 @@ def _expand_matrix_constraints(matrix_config):
if any(test_spec.satisfies(x) for x in excludes): if any(test_spec.satisfies(x) for x in excludes):
continue continue
if sigil: # If no broadcast, this is [(,)].
flat_combo[0] = Spec(sigil + str(flat_combo[0])) # It will run once, as required, and apply no constraints
for broadcast_combo in broadcast_constraints:
final_combo = [_apply_broadcast(spec.copy(), broadcast_combo) for spec in flat_combo]
# Add to list of constraints if sigil:
results.append(flat_combo) final_combo[0] = Spec(sigil + str(final_combo[0]))
# Add to list of constraints
results.append(final_combo)
return results return results
def _apply_broadcast(spec, constraints):
if constraints:
for node in spec.traverse():
if node.name:
for constraint in constraints:
node.constrain(constraint)
return spec
def _sigilify(item, sigil): def _sigilify(item, sigil):
if isinstance(item, dict): if isinstance(item, dict):
if sigil: if sigil:

View File

@ -214,3 +214,12 @@ def test_spec_list_constraints_with_structure(
speclist = SpecList("specs", [matrix]) speclist = SpecList("specs", [matrix])
assert len(speclist.specs) == 1 assert len(speclist.specs) == 1
assert libdwarf_spec in speclist.specs[0] assert libdwarf_spec in speclist.specs[0]
def test_spec_list_broadcast(self, mock_packages):
matrix = {"matrix": [["mpileaks"], ["^callpath"]], "broadcast": [["%gcc", "%clang"]]}
speclist = SpecList("specs", [matrix])
assert len(speclist) == 2
for spec in speclist:
for node in spec.traverse():
assert node.compiler.name == spec.compiler.name