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

try fallback for dl on keyerror + ruffage #916

Merged
merged 1 commit into from
Oct 24, 2024
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
45 changes: 23 additions & 22 deletions pyphare/pyphare/pharesee/run/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import glob
import numpy as np

from pyphare.pharesee.hierarchy import hierarchy_from
Expand All @@ -9,7 +10,6 @@
from pyphare.core.phare_utilities import listify

from pyphare.logger import getLogger
from .utils import _current1d
from .utils import (
_compute_to_primal,
_compute_pop_pressure,
Expand All @@ -36,8 +36,6 @@
def __init__(self, path, default_time=None):
self.path = path
self.default_time_ = default_time
import glob

self.available_diags = glob.glob(os.path.join(self.path, "*.h5"))

def _get_hierarchy(self, times, filename, hier=None, **kwargs):
Expand Down Expand Up @@ -92,7 +90,7 @@
return self._get(hier, time, merged, "nearest")

def GetB(self, time, merged=False, interp="nearest", all_primal=True, **kwargs):
if merged == True:
if merged:
all_primal = False
hier = self._get_hierarchy(time, "EM_B.h5", **kwargs)
if not all_primal:
Expand All @@ -102,7 +100,7 @@
return VectorField(h)

def GetE(self, time, merged=False, interp="nearest", all_primal=True, **kwargs):
if merged == True:
if merged:
all_primal = False
hier = self._get_hierarchy(time, "EM_E.h5", **kwargs)
if not all_primal:
Expand Down Expand Up @@ -164,7 +162,7 @@
return ScalarField(h) * Te

def GetJ(self, time, merged=False, interp="nearest", all_primal=True, **kwargs):
if merged == True:
if merged:
all_primal = False
B = self.GetB(time, all_primal=False, **kwargs)
J = compute_hier_from(_compute_current, B)
Expand Down Expand Up @@ -239,16 +237,9 @@
:param level: the level at which get the associated grid size
:param time: the time because level depends on it
"""
import glob

h5_time_grp_key = "t"
files = self.available_diags
any_file = files[0]
h5_filename = any_file
import h5py

data_file = h5py.File(h5_filename, "r")

def _get_time():
if time:
return time
Expand All @@ -257,21 +248,31 @@
self.default_time_ = float(list(data_file[h5_time_grp_key].keys())[0])
return self.default_time_

time = _get_time()
h5_time_grp_key = "t"
files = self.available_diags

hier = self._get_hierarchy(time, h5_filename.split("/")[-1])
for h5_filename in files:
data_file = h5py.File(h5_filename, "r")

if level == "finest":
level = hier.finest_level(time)
fac = np.power(hier.refinement_ratio, level)
time = _get_time()

root_cell_width = np.asarray(data_file.attrs["cell_width"])
try:
hier = self._get_hierarchy(time, h5_filename.split("/")[-1])

if level == "finest":
level = hier.finest_level(time)
fac = np.power(hier.refinement_ratio, level)

root_cell_width = np.asarray(data_file.attrs["cell_width"])

return root_cell_width / fac

except KeyError:
... # time may not be avilaable for given quantity

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

return root_cell_width / fac
raise RuntimeError("Unable toGetDl")
PhilipDeegan marked this conversation as resolved.
Show resolved Hide resolved

def all_times(self):
from glob import glob
import os
import h5py

files = self.available_diags
Expand Down
4 changes: 2 additions & 2 deletions pyphare/pyphare/simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def setup(self):
self.cpp_hier,
)
return self
except:
except Exception:
import sys
import traceback

Expand All @@ -137,7 +137,7 @@ def initialize(self):
self._auto_dump() # first dump might be before first advance

return self
except:
except Exception:
import sys

print(
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/tdtagged/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ endif()
if(HighFive)

## These test use dump diagnostics so require HighFive!
phare_python3_exec(11 test-td-tagged td1dtagged.py ${CMAKE_CURRENT_BINARY_DIR})
phare_python3_exec(11 test-td-tagged td1dtagged.py ${CMAKE_CURRENT_BINARY_DIR})

endif()
13 changes: 5 additions & 8 deletions tests/functional/tdtagged/td1dtagged.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import matplotlib as mpl
import numpy as np

mpl.use("Agg")
from tests.simulator.test_advance import AdvanceTestBase
from tests.diagnostic import all_timestamps
from pyphare.cpp import cpp_lib

cpp = cpp_lib()

from tests.diagnostic import all_timestamps
mpl.use("Agg")


def density(x):
Expand Down Expand Up @@ -240,12 +243,6 @@ def by_fit(x, x0, L):
raise RuntimeError(f"x0 (={x0}) too far from 172")


from tests.simulator.test_advance import AdvanceTestBase
from pyphare.cpp import cpp_lib

cpp = cpp_lib()


test = AdvanceTestBase()


Expand Down
Loading