Skip to content

Commit

Permalink
Fix #6143: determinant WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
git-user committed Jul 20, 2023
1 parent c507991 commit df60946
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions sirepo/template/silas.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
_RESULTS_FILE = "results{}.h5"
_CRYSTAL_FILE = "crystal{}.h5"
_MAX_H5_READ_TRIES = 3
_ABCD_DELTA = 1e-3


def background_percent_complete(report, run_dir, is_running):
Expand Down Expand Up @@ -135,6 +136,9 @@ def _data_url(path):
with open(path, "rb") as f:
return "data:image/jpeg;base64," + pkcompat.from_bytes(b64encode(f.read()))

def _determinant(matrix):
return matrix[2][0][0] * matrix[2][1][1] - matrix[2][0][1] * matrix[2][1][0]

n = Crystal(
params=PKDict(
l_scale=data.model.l_scale,
Expand Down Expand Up @@ -167,10 +171,9 @@ def _data_url(path):
axes[1].set_ylabel("N2")
plt.xlabel("Slice")
plt.savefig(p)
determinant = n[2][0][0]*n[2][1][1]-n[2][0][1]*n[2][1][0]
# TODO (gurhar1133):: check abs(determinant - 1) < delta
# where delta = 1e-3
pkdp("\n\n\n det={}\n\n\n\n", determinant)
d = _determinant(n)
if abs(d - 1) > _ABCD_DELTA:
raise AssertionError(f"The determinant of ABCD matrix should be 1, got determinant={d}")
return PKDict(
uri=_data_url(p),
A=round(n[2][0][0], 9),
Expand Down

0 comments on commit df60946

Please sign in to comment.