Skip to content
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
3 changes: 0 additions & 3 deletions INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,3 @@ Initial Setup and Installation

Troubleshooting
---------------

Please note that for ATIP to function with Python 3.7 or later, you must
use Cothread>=2.16.
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
("py:class", "obj"),
("py:class", "class"),
("py:class", "at.lattice.lattice_object.Lattice"),
("py:class", "cothread.Event"),
]

# Both the class’ and the __init__ method’s docstring are concatenated and
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = "Accelerator Toolbox Interface for Pytac"
dependencies = [
"numpy",
"scipy",
"pytac>=1.1.0",
"pytac>=2.0.0",
"accelerator-toolbox>=0.8.0",
"cothread",
"softioc",
Expand All @@ -35,6 +35,7 @@ dev = [
"pydata-sphinx-theme>=0.12",
"pytest",
"pytest-cov",
"pytest-asyncio",
"testfixtures",
"ruff",
"sphinx-autobuild",
Expand Down Expand Up @@ -73,6 +74,7 @@ addopts = """
filterwarnings = "error"
# Doctest python code in docs, python code in src docstrings, test functions in tests
testpaths = "docs src tests"
asyncio_mode = "auto"

[tool.coverage.run]
data_file = "/tmp/atip.coverage"
Expand Down
27 changes: 22 additions & 5 deletions src/atip/__main__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
"""Interface for ``python -m atip``."""

import asyncio
import logging
from argparse import ArgumentParser
from collections.abc import Sequence

from atip import __version__
import atip

__all__ = ["main"]


def main(args: Sequence[str] | None = None) -> None:
async def async_main() -> None:
"""Argument parser for the CLI."""
parser = ArgumentParser()
parser.add_argument(
"-v",
"--version",
action="version",
version=__version__,
version=atip.__version__,
)
parser.parse_args(args)
parser.add_argument(
"-t",
"--run-test",
help="Start an endless test of atip",
action="store_true",
)
args = parser.parse_args()

if args.run_test:
await atip.utils.test_atip()


def main() -> None:
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
# Load the AT sim into the Pytac lattice.
asyncio.run(async_main())


if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions src/atip/load_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
SIMULATED_FIELDS = {"a1", "b0", "b1", "b2", "b3", "x", "y", "f", "x_kick", "y_kick"}


def load_from_filepath(
async def load_from_filepath(
pytac_lattice,
at_lattice_filepath,
sim_params=None,
Expand All @@ -36,17 +36,17 @@ def load_from_filepath(
at_lattice = at.load.load_mat(
at_lattice_filepath,
name=pytac_lattice.name,
energy=pytac_lattice.get_value("energy", units=pytac.PHYS),
energy=await pytac_lattice.get_value("energy", units=pytac.PHYS),
)
return load(
return await load(
pytac_lattice,
at_lattice,
sim_params,
callback,
)


def load(
async def load(
pytac_lattice,
at_lattice,
sim_params=None,
Expand All @@ -72,7 +72,7 @@ def load(
f"(AT:{len(at_lattice)} Pytac:{len(pytac_lattice)})."
)
# Initialise an instance of the ATSimulator Object.
atsim = ATSimulator(
atsim = await ATSimulator.create(
at_lattice,
sim_params,
callback,
Expand Down
12 changes: 6 additions & 6 deletions src/atip/sim_data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def add_field(self, field):
else:
self._fields.append(field)

def get_value(self, field, handle=None, throw=True):
async def get_value(self, field, handle=None, throw=True):
"""Get the value for a field.

Args:
Expand All @@ -150,7 +150,7 @@ def get_value(self, field, handle=None, throw=True):
# Wait for any outstanding calculations to conclude, to ensure they are
# complete before a value is returned; if the wait times out then raise
# an error message or log a warning according to the value of throw.
if not self._atsim.wait_for_calculations():
if not await self._atsim.wait_for_calculations():
error_msg = "Check for completion of outstanding calculations timed out."
if throw:
raise ControlSystemException(error_msg)
Expand All @@ -162,7 +162,7 @@ def get_value(self, field, handle=None, throw=True):
else:
raise FieldException(f"No field {field} on AT element {self._at_element}.")

def set_value(self, field, value, throw=None):
async def set_value(self, field, value, throw=None):
"""Set the value for a field. The field and value go onto the queue of
changes on the ATSimulator to be passed to make_change when the queue
is emptied.
Expand All @@ -180,7 +180,7 @@ def set_value(self, field, value, throw=None):
"""
if field in self._fields:
if field in self._set_field_funcs.keys():
self._atsim.queue_set(self._make_change, field, value)
await self._atsim.queue_set(self._make_change, field, value)
else:
raise HandleException(
f"Field {field} cannot be set on element data source {self}."
Expand Down Expand Up @@ -415,7 +415,7 @@ def get_fields(self):
"""
return list(self._field_funcs.keys())

def get_value(self, field, handle=None, throw=True):
async def get_value(self, field, handle=None, throw=True):
"""Get the value for a field on the Pytac lattice.

Args:
Expand All @@ -440,7 +440,7 @@ def get_value(self, field, handle=None, throw=True):
# Wait for any outstanding calculations to conclude, to ensure they are
# complete before a value is returned; if the wait times out then raise
# an error message or log a warning according to the value of throw.
if not self._atsim.wait_for_calculations():
if not await self._atsim.wait_for_calculations():
error_msg = "Check for completion of outstanding calculations timed out."
if throw:
raise ControlSystemException(error_msg)
Expand Down
Loading
Loading