Skip to content

Commit

Permalink
Revert "Add properties via pydantic"
Browse files Browse the repository at this point in the history
This reverts commit 7204199.
  • Loading branch information
jank324 committed Sep 12, 2023
1 parent 237136a commit 20defef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 54 deletions.
55 changes: 2 additions & 53 deletions cheetah/accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pydantic
import torch
from matplotlib.patches import Rectangle
from scipy import constants
Expand All @@ -28,7 +27,7 @@
)


class Element(ABC, pydantic.BaseModel):
class Element(ABC):
"""
Base class for elements of particle accelerators.
Expand All @@ -37,10 +36,7 @@ class Element(ABC, pydantic.BaseModel):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

name: str = "unnamed"
device: torch.device

def __init__(self, name: str = "unnamed", device: str = "auto") -> None:
def __init__(self, name: Optional[str] = None, device: str = "auto") -> None:
self.name = name

if device == "auto":
Expand Down Expand Up @@ -172,8 +168,6 @@ class Drift(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

length: torch.Tensor

def __init__(
self, length: torch.Tensor, name: Optional[str] = None, device: str = "auto"
) -> None:
Expand Down Expand Up @@ -240,11 +234,6 @@ class Quadrupole(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

length: torch.Tensor
k1: torch.Tensor = torch.tensor(0.0)
misalignment: torch.Tensor = torch.tensor([0.0, 0.0])
tilt: torch.Tensor = torch.tensor(0.0)

def __init__(
self,
length: torch.Tensor,
Expand Down Expand Up @@ -341,15 +330,6 @@ class Dipole(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

length: torch.Tensor
angle: torch.Tensor = torch.tensor(0.0)
e1: torch.Tensor = torch.tensor(0.0)
e2: torch.Tensor = torch.tensor(0.0)
tilt: torch.Tensor = torch.tensor(0.0)
fringe_integral: torch.Tensor = torch.tensor(0.0)
fringe_integral_exit: Optional[torch.Tensor] = None
gap: torch.Tensor = torch.tensor(0.0)

def __init__(
self,
length: torch.Tensor,
Expand Down Expand Up @@ -580,9 +560,6 @@ class HorizontalCorrector(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

length: torch.Tensor
angle: torch.Tensor = torch.tensor(0.0)

def __init__(
self,
length: torch.Tensor,
Expand Down Expand Up @@ -663,9 +640,6 @@ class VerticalCorrector(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

length: torch.Tensor
angle: torch.Tensor = torch.tensor(0.0)

def __init__(
self,
length: torch.Tensor,
Expand Down Expand Up @@ -748,11 +722,6 @@ class Cavity(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

length: torch.Tensor
voltage: torch.Tensor = torch.tensor(0.0)
phase: torch.Tensor = torch.tensor(0.0)
frequency: torch.Tensor = torch.tensor(0.0)

def __init__(
self,
length: torch.Tensor,
Expand Down Expand Up @@ -1156,12 +1125,6 @@ class Screen(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

resolution: torch.Tensor = torch.tensor((1024, 1024))
pixel_size: torch.Tensor = torch.tensor((1e-3, 1e-3))
binning: torch.Tensor = torch.tensor(1)
misalignment: torch.Tensor = torch.tensor((0.0, 0.0))
is_active: bool = False

def __init__(
self,
resolution: torch.Tensor = torch.tensor((1024, 1024)),
Expand Down Expand Up @@ -1342,11 +1305,6 @@ class Aperture(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

x_max: torch.Tensor = torch.inf
y_max: torch.Tensor = torch.inf
shape: Literal["rectangular", "elliptical"] = "rectangular"
is_active: bool = True

def __init__(
self,
x_max: torch.Tensor = torch.inf,
Expand Down Expand Up @@ -1451,9 +1409,6 @@ class Undulator(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

length: torch.Tensor
is_active: bool = False

def __init__(
self,
length: torch.Tensor,
Expand Down Expand Up @@ -1530,10 +1485,6 @@ class Solenoid(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

length: torch.Tensor
k: torch.Tensor = torch.tensor(0.0)
misalignment: torch.Tensor = torch.tensor((0.0, 0.0))

def __init__(
self,
length: torch.Tensor = torch.tensor(0.0),
Expand Down Expand Up @@ -1625,8 +1576,6 @@ class Segment(Element):
CUDA GPU is selected if available. The CPU is used otherwise.
"""

elements: list[Element]

def __init__(
self, cell: list[Element], name: str = "unnamed", device: str = "auto"
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
long_description_content_type="text/markdown",
packages=["cheetah"],
python_requires=">=3.9",
install_requires=["matplotlib", "numpy", "pydantic", "scipy", "torch"],
install_requires=["matplotlib", "numpy", "scipy", "torch"],
)

0 comments on commit 20defef

Please sign in to comment.