Skip to content

Commit

Permalink
Merge branch 'streamlit/ui' of github.com:LemurPwned/cmtj into stream…
Browse files Browse the repository at this point in the history
…lit/ui
  • Loading branch information
LemurPwned committed Dec 22, 2024
2 parents ba2491e + f7164a9 commit 4b5aeeb
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 30 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,9 @@ on:
- 'setup.py'
- 'setup.cfg'
- 'pyproject.toml'
workflow_dispatch:
inputs:
linux:
type: boolean
required: true
default: true
other-os:
type: boolean
required: true
default: true

jobs:
linux-build:
if: ${{ inputs.linux }}
runs-on: ubuntu-latest
env:
TWINE_USERNAME: __token__
Expand All @@ -50,7 +39,6 @@ jobs:
continue-on-error: false

other-os-build:
if: ${{ inputs.other-os }}
runs-on: ${{ matrix.os }}
env:
TWINE_USERNAME: __token__
Expand Down Expand Up @@ -98,5 +86,5 @@ jobs:
run: |
gh release create "v${{ steps.get_version.outputs.version }}" \
--repo="$GITHUB_REPOSITORY" \
--title="${GITHUB_REPOSITORY#*/} v${{ steps.get_version.outputs.version }}" \
--title="${GITHUB_REPOSITORY#*/} ${{ steps.get_version.outputs.version }}" \
--generate-notes
12 changes: 8 additions & 4 deletions core/junction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,15 @@ template <typename T = double> class Layer {
// dm1/dm1x x m2 = (0, -mz, my)
// dm1/dm1y x m2 = (mz, 0, -mx)
// dm1/dm1z x m2 = (-my, mx, 0)
const CVector<T> dm1crossm2(
c_dot(Dvector, CVector<T>(0, -coupledMag.z, coupledMag.y)),
c_dot(Dvector, CVector<T>(coupledMag.z, 0, -coupledMag.x)),
c_dot(Dvector, CVector<T>(-coupledMag.y, coupledMag.x, 0)));
// E = D z * (m1 x m2) == D m1 (m2 x z)
// dE/dm1 = D m2 x z
const CVector<T> dm1crossm2 = -1.0 * c_cross<T>(Dvector, coupledMag);
return dm1crossm2 / (this->Ms * this->thickness);
// const CVector<T> dm1crossm2(
// c_dot(Dvector, CVector<T>(0, -coupledMag.z, coupledMag.y)),
// c_dot(Dvector, CVector<T>(coupledMag.z, 0, -coupledMag.x)),
// c_dot(Dvector, CVector<T>(-coupledMag.y, coupledMag.x, 0)));
// return dm1crossm2 / (this->Ms * this->thickness);
}

CVector<T> calculateIDMI(T time, const CVector<T> &stepMag,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from setuptools import Extension, find_namespace_packages, setup
from setuptools.command.build_ext import build_ext

__version__ = "1.6.1"
__version__ = "1.6.2"
"""
As per
https://github.com/pybind/python_example
Expand Down
6 changes: 5 additions & 1 deletion view/simulation_fns.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def create_single_domain(id_: str) -> Layer:

def create_single_layer(id_: str) -> tuple:
"""Do not forget to rescale the units!"""
demag = [CVector(0, 0, 0), CVector(0, 0, 0), CVector(0, 0, 1)]
demag = [
CVector(st.session_state[f"Nxx{id_}"] * 1e-6, 0, 0),
CVector(0, st.session_state[f"Nyy{id_}"] * 1e-6, 0),
CVector(0, 0, st.session_state[f"Nzz{id_}"] * 1e-6),
]
Kdir = FieldScan.angle2vector(
theta=st.session_state[f"theta_K{id_}"], phi=st.session_state[f"phi_K{id_}"]
)
Expand Down
77 changes: 66 additions & 11 deletions view/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
from autofit import autofit
from helpers import simulate_pimm, simulate_vsd
from utils import GENERIC_BOUNDS, GENERIC_UNITS
import json


def export_session_state():
export_dict = {}
opts = ["_btn", "_file", "_state", "low_", "up_", "check_", "upload"]
for k, v in st.session_state.items():
skip = any(forb_opts in k for forb_opts in opts)
if not skip:
export_dict[k] = v

return json.dumps(export_dict)


def import_session_state(file):
for k, v in json.load(file).items():
st.session_state[k] = v


with st.expander("# Read me"):
st.write(
Expand All @@ -17,13 +35,32 @@
)

with st.sidebar:
st.file_uploader(
"Upload your data here",
help="Upload your data here. Must be `\t` separated values and have H and f headers.",
type=["txt", "dat"],
accept_multiple_files=False,
key="upload",
)
with st.expander("Export/Import"):
st.download_button(
label="Export session state",
data=export_session_state(),
file_name="session_state.json",
mime="application/json",
type="primary",
)

st.file_uploader(
"Upload session state",
help="Upload your data here. Must be `\t` separated values and have H and f headers.",
type=["json"],
accept_multiple_files=False,
key="import_file",
)
if st.session_state.import_file:
import_session_state(st.session_state.import_file)

st.file_uploader(
"Upload your data here",
help="Upload your data here. Must be `\t` separated values and have H and f headers.",
type=["txt", "dat"],
accept_multiple_files=False,
key="upload",
)
N = st.number_input(
"Number of layers", min_value=1, max_value=10, value=1, key="N", format="%d"
)
Expand Down Expand Up @@ -95,6 +132,25 @@
key=f"phi_K{i}",
help="Azimuthal angle of the anisotropy axis",
)
st.write("Demagnetization field")
st.number_input(
f"Nxx ({i+1})",
value=0.0,
key=f"Nxx{i}",
format="%0.5f",
)
st.number_input(
f"Nyy ({i+1})",
value=0.0,
key=f"Nyy{i}",
format="%0.5f",
)
st.number_input(
f"Nzz ({i+1})",
value=1.0,
key=f"Nzz{i}",
format="%0.5f",
)
st.markdown("-----\n")

with st.expander("Interlayer parameters"):
Expand Down Expand Up @@ -150,7 +206,6 @@
help="Maximum frequency (cutoff) visible in plot",
)


pimm_tab, vsd_tab, opt_tab = st.tabs(["PIMM", "VSD", "Optimization"])
with opt_tab:
with st.expander("Optimization parameters"):
Expand Down Expand Up @@ -275,9 +330,9 @@
st.button("Simulate PIMM", on_click=simulate_pimm, key="PIMM_btn")
st.number_input(
"Hoe (kA/m)",
min_value=0.05,
max_value=50.0,
value=0.05,
min_value=-500.0,
max_value=500.0,
value=50.0,
key="Hoe_mag",
help="Magnitude of the Oersted field impulse (PIMM excitation)",
)
Expand Down

0 comments on commit 4b5aeeb

Please sign in to comment.