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

Hotfix/submodules #70

Merged
merged 2 commits into from
May 15, 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
19 changes: 19 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*.jpg
*.png
deprecated/
build/
scratch/
*.egg-info/
__pycache__/
*.pyc
*.pyo
*.pyd
*.so
.eggs/
.ipynb_checkpoints/
.vscode/
.idea/
assets/
articles/
examples/
docs/
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include cmtj/__init__.pyi
include cmtj/py.typed
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ python3 -m pip install cmtj
3. Straight from source:

```bash
python3 -m pip install https://github.com/LemurPwned/cmtj.git
python3 -m pip install git+https://github.com/LemurPwned/cmtj.git
```

4. Clone the repository:
Expand All @@ -84,7 +84,7 @@ The package requires (if `utils` subpackage is used):

## Documentation and examples

Documentation: [https://lemurpwned.github.io/cmtj](https://lemurpwned.github.io/cmtj)
Documentation: [https://lemurpwned.github.io/cmtj](https://lemurpwned.github.io/cmtj).
There are many examples available, check out the [examples section in the docs](https://lemurpwned.github.io/cmtj/experimental-methods/introduction/)

## Extensions
Expand Down
20 changes: 6 additions & 14 deletions cmtj/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,17 @@ class Junction:
:param SMR_Y: Spin magnetoresistance transverse
:param AHE: Anomalous Hall effect resistance offset (transverse only)
"""
...

@overload
def __init__(*args, **kwargs) -> Any: ...
def clearLog(self) -> Dict[str, Any]:
"""
Reset current simulation state`
"""
"""Reset current simulation state."""
...

def getLayerMagnetisation(self, layer_id: str) -> CVector: ...
def getLog(self) -> Dict[str, List[float]]:
"""
Retrieve the simulation log [data].
"""
"""Retrieve the simulation log [data]."""
...

def getMagnetoresistance(self) -> List[float]: ...
Expand Down Expand Up @@ -329,7 +326,7 @@ class Layer:
demagTensor: List[CVector],
temperature: float = ...,
damping: float = ...,
) -> None:
) -> Layer:
"""
The basic structure is a magnetic layer.
Its parameters are defined by the constructor and may be altered
Expand All @@ -342,7 +339,6 @@ class Layer:
:param Ms: magnetisation saturation. Unit: Tesla [T].
:param thickness: thickness of the layer. Unit: meter [m].
:param cellSurface: surface of the layer, for volume calculation. Unit: meter^2 [m^2].
:param dipoleTensor: dipole tensor of the layer.
:param damping: often marked as alpha in the LLG equation. Damping of the layer. Default 0.011. Dimensionless
"""
...
Expand All @@ -359,7 +355,7 @@ class Layer:
damping: float = 0.11,
fieldLikeTorque: float = 0,
dampingLikeTorque: float = 0,
) -> "Layer":
) -> Layer:
"""
Create SOT layer -- including damping and field-like torques that are
calculated based on the effective Spin Hall angles.
Expand All @@ -369,7 +365,6 @@ class Layer:
:param Ms: magnetisation saturation. Unit: Tesla [T].
:param thickness: thickness of the layer. Unit: meter [m].
:param cellSurface: surface of the layer, for volume calculation. Unit: meter^2 [m^2].
:param dipoleTensor: dipole tensor of the layer.
:param temperature: resting temperature of the layer. Unit: Kelvin [K].
:param damping: often marked as alpha in the LLG equation. Damping of the layer. Default 0.011. Dimensionless.
"""
Expand All @@ -388,7 +383,7 @@ class Layer:
SlonczewskiSpacerLayerParameter: float = 1.0,
beta: float = 0.0,
spinPolarisation: float = 0.0,
) -> "Layer":
) -> Layer:
"""
Create STT layer -- with the standard Slomczewski formulation.
:param id: identifiable name for a layer -- e.g. "bottom" or "free".
Expand All @@ -397,7 +392,6 @@ class Layer:
:param Ms: magnetisation saturation. Unit: Tesla [T].
:param thickness: thickness of the layer. Unit: meter [m].
:param cellSurface: surface of the layer, for volume calculation. Unit: meter^2 [m^2].
:param dipoleTensor: dipole tensor of the layer.
:param damping: often marked as alpha in the LLG equation. Damping of the layer. Default 0.011. Dimensionless.
:param SlonczewskiSpacerLayerParameter: Slomczewski parameter. Often marked as lambda.
:param beta: beta parameter that scales FL/DL ratio.
Expand Down Expand Up @@ -469,7 +463,6 @@ class ScalarDriver:
"""
Constant driver produces a constant signal of a fixed amplitude.
:param constantValue: constant value of the driver (constant offset/amplitude)

"""
...

Expand Down Expand Up @@ -497,7 +490,6 @@ class ScalarDriver:
:param amplitude: amplitude of the sine wave
:param frequency: frequency of the sine
:param phase: phase of the sine in radians.

"""
...

Expand Down
51 changes: 51 additions & 0 deletions cmtj/llgb/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from typing import Dict, List, Tuple

import cmtj

class LLGBJunction:
def __init__(self, layers: List[LLGBLayer]) -> None: ...
def clearLog(self) -> None: ...
def getLog(self) -> Dict[str, List[float]]: ...
def runSimulation(
self,
totalTime: float,
timeStep: float = ...,
writeFrequency: float = ...,
log: bool = ...,
solverMode: cmtj.SolverMode = ...,
) -> None: ...
def saveLogs(self, arg0: str) -> None: ...
def setLayerExternalFieldDriver(
self, arg0: str, arg1: cmtj.AxialDriver
) -> None: ...
def setLayerTemperatureDriver(self, arg0: str, arg1: cmtj.ScalarDriver) -> None: ...

class LLGBLayer:
def __init__(
self,
id: str,
mag: cmtj.CVector,
anis: cmtj.CVector,
Ms: float,
thickness: float,
cellSurface: float,
demagTensor: List[cmtj.CVector],
damping: float,
Tc: float,
susceptibility: float,
me: float,
) -> None: ...
def setAnisotropyDriver(self, arg0: cmtj.ScalarDriver) -> None: ...
def setExternalFieldDriver(self, arg0: cmtj.AxialDriver) -> None: ...
def setTemperatureDriver(self, arg0: cmtj.ScalarDriver) -> None: ...

def MFAWeissCurie(
me: float,
T: float,
J0: float,
relax: float = ...,
tolerance: float = ...,
maxIter: int = ...,
) -> Tuple[float, float]: ...
def langevin(arg0: float) -> float: ...
def langevinDerivative(arg0: float) -> float: ...
11 changes: 9 additions & 2 deletions cmtj/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class VectorObj:
:param phi: positive x-axis (in xy plane) angle in radians
:param mag: magnitude of the vector, if not set defaults to 1 *unit vector*
"""

theta: float # in radians
phi: float # rad
mag: float = 1
Expand All @@ -41,7 +42,8 @@ def __hash__(self) -> int:
return hash(str(self))

def __eq__(self, __value: "VectorObj") -> bool:
return self.theta == __value.theta and self.phi == __value.phi and self.mag == __value.mag
return (self.theta == __value.theta and self.phi == __value.phi
and self.mag == __value.mag)

def _componentwise_mul(self, other):
coors = self.get_cartesian()
Expand All @@ -61,13 +63,16 @@ def from_spherical(theta, phi, mag=1):
"""Creates a Cartesian vector from spherical components"""
return [
mag * math.sin(theta) * math.cos(phi),
mag * math.sin(theta) * math.sin(phi), mag * math.cos(theta)
mag * math.sin(theta) * math.sin(phi),
mag * math.cos(theta),
]

@staticmethod
def from_cartesian(x: float, y: float, z: float):
"""Creates a spherical vector from Cartesian components"""
mag = math.sqrt(x**2 + y**2 + z**2)
if mag == 0:
return VectorObj(0, 0, 0)
theta = math.acos(z / mag)
phi = math.atan2(y, x)
return VectorObj(theta, phi, mag)
Expand All @@ -76,6 +81,8 @@ def from_cartesian(x: float, y: float, z: float):
def from_cvector(cvector: CVector):
"""Creates a spherical vector from Cartesian components"""
mag = cvector.length()
if mag == 0:
return VectorObj(0, 0, 0)
theta = math.acos(cvector.z / mag)
phi = math.atan2(cvector.y, cvector.x)
return VectorObj(theta, phi, mag)
Expand Down
22 changes: 22 additions & 0 deletions docker/Dockerfile.wheel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.9

# let's copy all the necessary files
# we install our only 2 dependencies :) and vim for nice workflow
RUN apt-get update && \
apt-get install -y build-essential libfftw3-dev git python3 python3-pip vim
RUN python3 -m pip install --upgrade pip
WORKDIR /scratch

COPY setup.py /scratch
COPY setup.cfg /scratch
COPY python /scratch/python
COPY core /scratch/core
COPY third_party /scratch/third_party
COPY cmtj /scratch/cmtj

RUN python3 -m setup bdist_wheel && \
python3 -m pip install dist/*.whl numpy scipy tqdm

WORKDIR /app
RUN python3 -c "import cmtj; from cmtj.utils import FieldScan" && \
python3 -c "import cmtj; from cmtj import Layer"
22 changes: 19 additions & 3 deletions docs/docgen.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import glob
import logging
import os
import re
from dataclasses import dataclass

log = logging.getLogger("mkdocs")

py_signature = r"(def (.+?) -> ([\'\[\]\,\sA-z]+)\:)"
c_py_signature = re.compile(py_signature)

joint_py = r"(?s)(def (.+?) -> ([\'\[\]\,\sA-z]+)\:)\n{0,}\s{8}(\"{3}(.+?)\"{3})"
# old regex that does not allow for optional docstrings and quoted rtype
# joint_py = r"(?s)(def (.+?) -> ([\"\'\[\]\,\sA-z]+)\:)\n{0,}\s{8}(\"{3}(.+?)\"{3})"
joint_py = r"(?s)(def (.+?) -> ([\"\'\[\]\,\sA-z]+)\:)(?:\n\s*(\"{3}(.+?)\"{3}))?"
c_joint_py = re.compile(joint_py)

pydoc_regex = r"(?s)(\"{3}(.+?)\"{3})"
Expand Down Expand Up @@ -81,6 +86,7 @@ def py_signature_to_markdown(self):

def extract_python_docs(file_text):
for captured in c_joint_py.findall(file_text):
print(captured)
if captured:
yield PythonDocstring(
signature=captured[1].strip().replace("\n", ""),
Expand Down Expand Up @@ -109,10 +115,16 @@ def create_api_markdown_file(src_filename):

class_docs = ftext.split("class")[1:]
for i, doc_ in enumerate(class_docs):
doc_ = (
doc_.strip()
.replace("@staticmethod", "")
.replace("@classmethod", "")
.replace("@overload", "")
)
class_name = doc_.partition("\n")[0].replace(":", "").strip()
print(i, class_name)
md_fn += f"## `{class_name}`"
for g in extract_python_docs(doc_):
for g in extract_python_docs(doc_.replace("...", "...\n")):
sig = g.py_signature_to_markdown()
md_fn += f"\n{sig}\n"
md_fn += " \n"
Expand All @@ -123,10 +135,14 @@ def create_api_markdown_file(src_filename):
f.write(md_fn)


if __name__ == "__main__":
def on_startup(command, dirty, **kwargs):
fn_lists = [
*glob.glob(os.path.join(os.path.dirname(__file__), "..", "cmtj/*/*.pyi")),
*glob.glob(os.path.join(os.path.dirname(__file__), "..", "cmtj/*.pyi")),
]
for fn in fn_lists:
create_api_markdown_file(fn)


if __name__ == "__main__":
on_startup()
Loading
Loading