Skip to content

Commit

Permalink
MFlowCode#474: Kickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleberre committed Jul 4, 2024
1 parent 37b8838 commit 3107d60
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
4 changes: 2 additions & 2 deletions examples/2D_isentropicvortex/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
'x_domain%end' : 3,
'y_domain%beg' : -3,
'y_domain%end' : 3,
'stretch_x' : True,
'stretch_y' : True,
'stretch_x' : 'T',
'stretch_y' : 'T',
'loops_x' : 2,
'loops_y' : 2,
'a_x' : 1.03,
Expand Down
13 changes: 7 additions & 6 deletions toolchain/mfc/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from .printer import cons


MFC_ROOTDIR = abspath(normpath(f"{dirname(realpath(__file__))}/../.."))
MFC_TESTDIR = abspath(f"{MFC_ROOTDIR}/tests")
MFC_SUBDIR = abspath(f"{MFC_ROOTDIR}/build")
MFC_TEMPLATEDIR = abspath(f"{MFC_ROOTDIR}/toolchain/templates")
MFC_LOCK_FILEPATH = abspath(f"{MFC_SUBDIR}/lock.yaml")
MFC_BENCH_FILEPATH = abspath(f"{MFC_ROOTDIR}/toolchain/bench.yaml")
MFC_ROOTDIR = abspath(normpath(f"{dirname(realpath(__file__))}/../.."))
MFC_TESTDIR = abspath(f"{MFC_ROOTDIR}/tests")
MFC_SUBDIR = abspath(f"{MFC_ROOTDIR}/build")
MFC_TEMPLATEDIR = abspath(f"{MFC_ROOTDIR}/toolchain/templates")
MFC_LOCK_FILEPATH = abspath(f"{MFC_SUBDIR}/lock.yaml")
MFC_BENCH_FILEPATH = abspath(f"{MFC_ROOTDIR}/toolchain/bench.yaml")
MFC_EXAMPLE_DIRPATH = abspath(f"{MFC_ROOTDIR}/examples")

MFC_LOGO = """\
.=++*: -+*+=.
Expand Down
32 changes: 20 additions & 12 deletions toolchain/mfc/test/case.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os, glob, typing, hashlib, binascii, subprocess, itertools, dataclasses
import os, glob, hashlib, binascii, subprocess, itertools, dataclasses

from typing import List, Set, Union, Callable

from .. import case, common
from ..state import ARG
Expand Down Expand Up @@ -102,13 +104,13 @@ class TestCase(case.Case):
trace: str
rebuild: bool

def __init__(self, trace: str, mods: dict, ppn: int = None, rebuild: bool = None) -> None:
def __init__(self, trace: str, mods: dict, ppn: int = None, rebuild: bool = False) -> None:
self.trace = trace
self.ppn = ppn or 1
self.rebuild = rebuild or False
self.rebuild = rebuild
super().__init__({**BASE_CFG.copy(), **mods})

def run(self, targets: typing.List[typing.Union[str, MFCTarget]], gpus: typing.Set[int]) -> subprocess.CompletedProcess:
def run(self, targets: List[Union[str, MFCTarget]], gpus: Set[int]) -> subprocess.CompletedProcess:
if gpus is not None and len(gpus) != 0:
gpus_select = ["--gpus"] + [str(_) for _ in gpus]
else:
Expand Down Expand Up @@ -232,16 +234,17 @@ def compute_tolerance(self) -> float:
class TestCaseBuilder:
trace: str
mods: dict
path: str
args: typing.List[str]
path: str | None
args: List[str] | None
ppn: int
rebuild: bool
functor: Callable | None

def get_uuid(self) -> str:
return trace_to_uuid(self.trace)

def to_case(self) -> TestCase:
dictionary = self.mods.copy()
dictionary = {}
if self.path:
dictionary.update(input.load(self.path, self.args).params)

Expand All @@ -253,7 +256,12 @@ def to_case(self) -> TestCase:
path = os.path.abspath(path)
if os.path.exists(path):
dictionary[key] = path
break

dictionary.update(self.mods)

if self.functor:
self.functor(dictionary)
print(dictionary)

return TestCase(self.trace, dictionary, self.ppn, self.rebuild)

Expand All @@ -277,11 +285,11 @@ def pop(self) -> None:
return (self.mods.pop(), self.trace.pop())


def define_case_f(trace: str, path: str, args: typing.List[str] = None, ppn: int = None, rebuild: bool = None) -> TestCaseBuilder:
return TestCaseBuilder(trace, {}, path, args or [], ppn, rebuild)
def define_case_f(trace: str, path: str, args: List[str] = None, newMods: dict = None, ppn: int = None, rebuild: bool = False, functor: Callable = None) -> TestCaseBuilder:
return TestCaseBuilder(trace, newMods or {}, path, args or [], ppn, rebuild, functor)


def define_case_d(stack: CaseGeneratorStack, newTrace: str, newMods: dict, ppn: int = None, rebuild: bool = None) -> TestCaseBuilder:
def define_case_d(stack: CaseGeneratorStack, newTrace: str, newMods: dict, ppn: int = None, rebuild: bool = False, functor: Callable = None) -> TestCaseBuilder:
mods: dict = {}

for mod in stack.mods:
Expand All @@ -297,4 +305,4 @@ def define_case_d(stack: CaseGeneratorStack, newTrace: str, newMods: dict, ppn:
if not common.isspace(trace):
traces.append(trace)

return TestCaseBuilder(' -> '.join(traces), mods, None, None, ppn, rebuild)
return TestCaseBuilder(' -> '.join(traces), mods, None, [], ppn, rebuild, functor)
25 changes: 23 additions & 2 deletions toolchain/mfc/test/cases.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import typing, itertools
import os, typing, itertools

from mfc import common
from .case import define_case_d, CaseGeneratorStack, TestCaseBuilder
from .case import (
define_case_d, define_case_f,
CaseGeneratorStack, TestCaseBuilder
)

def get_bc_mods(bc: int, dimInfo):
params = {}
Expand Down Expand Up @@ -576,7 +579,25 @@ def foreach_dimension():
stack.pop()
stack.pop()

def foreach_example():
for path in os.listdir(common.MFC_EXAMPLE_DIRPATH):
if path == "scaling":
continue

name = f"{path.split('_')[0]} -> Example -> {'_'.join(path.split('_')[1:])}"
path = os.path.join(common.MFC_EXAMPLE_DIRPATH, path, "case.py")
if not os.path.isfile(path):
continue

def modify_example_case(case: dict):
case['t_step_save'] = 10

cases.append(define_case_f(name, path, [], {
't_step_stop': 100,
}, functor=modify_example_case))

foreach_dimension()
foreach_example()

# Sanity Check 1
if stack.size() != 0:
Expand Down

0 comments on commit 3107d60

Please sign in to comment.