Skip to content

Commit

Permalink
changed sim_signal_backend.py, SimSignalBackend to soft_signal_back…
Browse files Browse the repository at this point in the history
…end.py, `SoftSignalBackend`
  • Loading branch information
evalott100 committed Apr 18, 2024
1 parent 440bdb1 commit c5de76d
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/ophyd_async/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
wait_for_value,
)
from .signal_backend import SignalBackend
from .sim_signal_backend import SimSignalBackend
from .soft_signal_backend import SoftSignalBackend
from .standard_readable import StandardReadable
from .utils import (
DEFAULT_TIMEOUT,
Expand All @@ -54,7 +54,7 @@

__all__ = [
"SignalBackend",
"SimSignalBackend",
"SoftSignalBackend",
"DetectorControl",
"DetectorTrigger",
"DetectorWriter",
Expand Down
6 changes: 3 additions & 3 deletions src/ophyd_async/core/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from .async_status import AsyncStatus
from .device import Device
from .signal_backend import SignalBackend
from .sim_signal_backend import SimSignalBackend
from .soft_signal_backend import SoftSignalBackend
from .utils import DEFAULT_TIMEOUT, Callback, ReadingValueCallback, T

_sim_backends: Dict[Signal, SimSignalBackend] = {}
_sim_backends: Dict[Signal, SoftSignalBackend] = {}


def _add_timeout(func):
Expand Down Expand Up @@ -60,7 +60,7 @@ def set_name(self, name: str = ""):

async def connect(self, sim=False, timeout=DEFAULT_TIMEOUT):
if sim:
self._backend = SimSignalBackend(
self._backend = SoftSignalBackend(
datatype=self._init_backend.datatype, source=self._init_backend.source
)
_sim_backends[self] = self._backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}


class SimConverter(Generic[T]):
class SoftConverter(Generic[T]):
def value(self, value: T) -> T:
return value

Expand Down Expand Up @@ -50,7 +50,7 @@ def make_initial_value(self, datatype: Optional[Type[T]]) -> T:
return datatype()


class SimArrayConverter(SimConverter):
class SoftArrayConverter(SoftConverter):
def descriptor(self, source: str, value) -> Descriptor:
return {"source": source, "dtype": "array", "shape": [len(value)]}

Expand All @@ -65,7 +65,7 @@ def make_initial_value(self, datatype: Optional[Type[T]]) -> T:


@dataclass
class SimEnumConverter(SimConverter):
class SoftEnumConverter(SoftConverter):
enum_class: Type[Enum]

def write_value(self, value: Union[Enum, str]) -> Enum:
Expand All @@ -85,7 +85,7 @@ def make_initial_value(self, datatype: Optional[Type[T]]) -> T:
return cast(T, list(datatype.__members__.values())[0]) # type: ignore


class DisconnectedSimConverter(SimConverter):
class DisconnectedSoftConverter(SoftConverter):
def __getattribute__(self, __name: str) -> Any:
raise NotImplementedError("No PV has been set as connect() has not been called")

Expand All @@ -96,14 +96,14 @@ def make_converter(datatype):
is_enum = issubclass(datatype, Enum) if inspect.isclass(datatype) else False

if is_array or is_sequence:
return SimArrayConverter()
return SoftArrayConverter()
if is_enum:
return SimEnumConverter(datatype)
return SoftEnumConverter(datatype)

return SimConverter()
return SoftConverter()


class SimSignalBackend(SignalBackend[T]):
class SoftSignalBackend(SignalBackend[T]):
"""An simulated backend to a Signal, created with ``Signal.connect(sim=True)``"""

_value: T
Expand All @@ -116,7 +116,7 @@ def __init__(self, datatype: Optional[Type[T]], source: str) -> None:
self.source = f"sim://{pv}"
self.datatype = datatype
self.pv = source
self.converter: SimConverter = DisconnectedSimConverter()
self.converter: SoftConverter = DisconnectedSoftConverter()
self.put_proceeds = asyncio.Event()
self.put_proceeds.set()
self.callback: Optional[ReadingValueCallback[T]] = None
Expand Down
8 changes: 4 additions & 4 deletions src/ophyd_async/epics/pvi/pvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
get_type_hints,
)

from ophyd_async.core import Device, DeviceVector, SimSignalBackend
from ophyd_async.core import Device, DeviceVector, SoftSignalBackend
from ophyd_async.core.signal import Signal
from ophyd_async.core.utils import DEFAULT_TIMEOUT
from ophyd_async.epics._backend._p4p import PvaSignalBackend
Expand Down Expand Up @@ -172,8 +172,8 @@ def _sim_common_blocks(device: Device, stripped_type: Optional[Type] = None):

if is_device_vector:
if is_signal:
sub_device_1 = device_cls(SimSignalBackend(signal_dtype, device_name))
sub_device_2 = device_cls(SimSignalBackend(signal_dtype, device_name))
sub_device_1 = device_cls(SoftSignalBackend(signal_dtype, device_name))
sub_device_2 = device_cls(SoftSignalBackend(signal_dtype, device_name))
sub_device = DeviceVector({1: sub_device_1, 2: sub_device_2})
else:
sub_device = DeviceVector({1: device_cls(), 2: device_cls()})
Expand All @@ -185,7 +185,7 @@ def _sim_common_blocks(device: Device, stripped_type: Optional[Type] = None):
value.parent = sub_device
else:
if is_signal:
sub_device = device_cls(SimSignalBackend(signal_dtype, device_name))
sub_device = device_cls(SoftSignalBackend(signal_dtype, device_name))
else:
sub_device = device_cls()

Expand Down
4 changes: 2 additions & 2 deletions src/ophyd_async/sim/pattern_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from ophyd_async.core import DirectoryInfo, DirectoryProvider
from ophyd_async.core.signal import SignalR, observe_value
from ophyd_async.core.sim_signal_backend import SimSignalBackend
from ophyd_async.core.soft_signal_backend import SoftSignalBackend
from ophyd_async.core.utils import DEFAULT_TIMEOUT

# raw data path
Expand Down Expand Up @@ -158,7 +158,7 @@ def __init__(
self.written_images_counter: int = 0

# it automatically initializes to 0
self.signal_backend = SimSignalBackend(int, "sim://sim_images_counter")
self.signal_backend = SoftSignalBackend(int, "sim://sim_images_counter")
self.sim_signal = SignalR(self.signal_backend)
blob = np.array(
generate_gaussian_blob(width=detector_width, height=detector_height)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_device_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def my_plan():

@pytest.mark.skip(
reason=(
"SimSignalBackend currently allows a different event-"
"SoftSignalBackend currently allows a different event-"
"loop to set the value, unlike real signals."
)
)
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_flyer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
DetectorWriter,
HardwareTriggeredFlyable,
SignalRW,
SimSignalBackend,
SoftSignalBackend,
TriggerInfo,
TriggerLogic,
)
Expand Down Expand Up @@ -51,7 +51,7 @@ async def stop(self):

class DummyWriter(DetectorWriter):
def __init__(self, name: str, shape: Sequence[int]):
self.dummy_signal = SignalRW(backend=SimSignalBackend(int, source="test"))
self.dummy_signal = SignalRW(backend=SoftSignalBackend(int, source="test"))
self._shape = shape
self._name = name
self._file: Optional[ComposeStreamResourceBundle] = None
Expand Down
12 changes: 6 additions & 6 deletions tests/core/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ophyd_async.core import (
Signal,
SignalRW,
SimSignalBackend,
SoftSignalBackend,
set_and_wait_for_value,
set_sim_put_proceeds,
set_sim_value,
Expand All @@ -26,7 +26,7 @@ async def connect(self, sim=False, timeout=DEFAULT_TIMEOUT):


def test_signals_equality_raises():
sim_backend = SimSignalBackend(str, "test")
sim_backend = SoftSignalBackend(str, "test")

s1 = MySignal(sim_backend)
s2 = MySignal(sim_backend)
Expand All @@ -45,7 +45,7 @@ def test_signals_equality_raises():


async def test_set_sim_put_proceeds():
sim_signal = Signal(SimSignalBackend(str, "test"))
sim_signal = Signal(SoftSignalBackend(str, "test"))
await sim_signal.connect(sim=True)

assert sim_signal._backend.put_proceeds.is_set() is True
Expand All @@ -63,7 +63,7 @@ async def time_taken_by(coro) -> float:


async def test_wait_for_value_with_value():
sim_signal = SignalRW(SimSignalBackend(str, "test"))
sim_signal = SignalRW(SoftSignalBackend(str, "test"))
sim_signal.set_name("sim_signal")
await sim_signal.connect(sim=True)
set_sim_value(sim_signal, "blah")
Expand All @@ -84,7 +84,7 @@ async def test_wait_for_value_with_value():


async def test_wait_for_value_with_funcion():
sim_signal = SignalRW(SimSignalBackend(float, "test"))
sim_signal = SignalRW(SoftSignalBackend(float, "test"))
sim_signal.set_name("sim_signal")
await sim_signal.connect(sim=True)
set_sim_value(sim_signal, 45.8)
Expand All @@ -110,7 +110,7 @@ def less_than_42(v):


async def test_set_and_wait_for_value():
sim_signal = SignalRW(SimSignalBackend(int, "test"))
sim_signal = SignalRW(SoftSignalBackend(int, "test"))
sim_signal.set_name("sim_signal")
await sim_signal.connect(sim=True)
set_sim_value(sim_signal, 0)
Expand Down
10 changes: 5 additions & 5 deletions tests/core/test_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
from bluesky.protocols import Reading

from ophyd_async.core import Signal, SignalBackend, SimSignalBackend, T
from ophyd_async.core import Signal, SignalBackend, SoftSignalBackend, T


class MyEnum(str, Enum):
Expand Down Expand Up @@ -93,7 +93,7 @@ async def test_backend_get_put_monitor(
put_value: T,
descriptor: Callable[[Any], dict],
):
backend = SimSignalBackend(datatype, "")
backend = SoftSignalBackend(datatype, "")

await backend.connect()
q = MonitorQueue(backend)
Expand All @@ -115,13 +115,13 @@ async def test_backend_get_put_monitor(


async def test_sim_backend_if_disconnected():
sim_backend = SimSignalBackend(npt.NDArray[np.float64], "SOME-IOC:PV")
sim_backend = SoftSignalBackend(npt.NDArray[np.float64], "SOME-IOC:PV")
with pytest.raises(NotImplementedError):
await sim_backend.get_value()


async def test_sim_backend_with_numpy_typing():
sim_backend = SimSignalBackend(npt.NDArray[np.float64], "SOME-IOC:PV")
sim_backend = SoftSignalBackend(npt.NDArray[np.float64], "SOME-IOC:PV")
await sim_backend.connect()

array = await sim_backend.get_value()
Expand All @@ -133,7 +133,7 @@ class myClass:
def __init__(self) -> None:
pass

sim_signal = Signal(SimSignalBackend(myClass, "test"))
sim_signal = Signal(SoftSignalBackend(myClass, "test"))
await sim_signal.connect(sim=True)

with pytest.raises(AssertionError):
Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
DirectoryInfo,
NotConnected,
SignalRW,
SimSignalBackend,
SoftSignalBackend,
StaticDirectoryProvider,
)
from ophyd_async.epics.signal import epics_signal_rw


class ValueErrorBackend(SimSignalBackend):
class ValueErrorBackend(SoftSignalBackend):
def __init__(self, exc_text=""):
self.exc_text = exc_text
super().__init__(int, "VALUE_ERROR_SIGNAL")
Expand All @@ -24,7 +24,7 @@ async def connect(self, timeout: float = DEFAULT_TIMEOUT):

class WorkingDummyChildDevice(Device):
def __init__(self, name: str = "working_dummy_child_device") -> None:
self.working_signal = SignalRW(backend=SimSignalBackend(int, "WORKING_SIGNAL"))
self.working_signal = SignalRW(backend=SoftSignalBackend(int, "WORKING_SIGNAL"))
super().__init__(name=name)


Expand Down
12 changes: 6 additions & 6 deletions tests/panda/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Device,
DeviceCollector,
SignalR,
SimSignalBackend,
SoftSignalBackend,
StaticDirectoryProvider,
set_sim_value,
)
Expand All @@ -30,10 +30,10 @@ async def sim_panda() -> PandA:
sim_panda.block1 = Device("BLOCK1") # type: ignore[attr-defined]
sim_panda.block2 = Device("BLOCK2") # type: ignore[attr-defined]
sim_panda.block1.test_capture = SignalRW( # type: ignore[attr-defined]
backend=SimSignalBackend(str, source="BLOCK1_capture")
backend=SoftSignalBackend(str, source="BLOCK1_capture")
)
sim_panda.block2.test_capture = SignalRW( # type: ignore[attr-defined]
backend=SimSignalBackend(str, source="BLOCK2_capture")
backend=SoftSignalBackend(str, source="BLOCK2_capture")
)

await asyncio.gather(
Expand Down Expand Up @@ -70,10 +70,10 @@ async def test_get_capture_signals_gets_all_signals(sim_panda):
async with DeviceCollector(sim=True):
sim_panda.test_seq = Device("seq")
sim_panda.test_seq.seq1_capture = SignalR(
backend=SimSignalBackend(str, source="seq1_capture")
backend=SoftSignalBackend(str, source="seq1_capture")
)
sim_panda.test_seq.seq2_capture = SignalR(
backend=SimSignalBackend(str, source="seq2_capture")
backend=SoftSignalBackend(str, source="seq2_capture")
)
await asyncio.gather(
sim_panda.test_seq.connect(),
Expand Down Expand Up @@ -181,7 +181,7 @@ async def test_numeric_blocks_correctly_formated(sim_writer: PandaHDFWriter):
async def get_numeric_signal(_):
return {
"device.block.1": CaptureSignalWrapper(
SignalR(backend=SimSignalBackend(str, source="test_signal")),
SignalR(backend=SoftSignalBackend(str, source="test_signal")),
Capture.Value,
)
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_flyer_with_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
DetectorWriter,
HardwareTriggeredFlyable,
SignalRW,
SimSignalBackend,
SoftSignalBackend,
)
from ophyd_async.core.detector import StandardDetector
from ophyd_async.core.device import DeviceCollector
Expand All @@ -28,7 +28,7 @@

class DummyWriter(DetectorWriter):
def __init__(self, name: str, shape: Sequence[int]):
self.dummy_signal = SignalRW(backend=SimSignalBackend(int, source="test"))
self.dummy_signal = SignalRW(backend=SoftSignalBackend(int, source="test"))
self._shape = shape
self._name = name
self._file: Optional[ComposeStreamResourceBundle] = None
Expand Down

0 comments on commit c5de76d

Please sign in to comment.