Skip to content

Commit

Permalink
Move contents of sim, and rename demo -> sim (#708)
Browse files Browse the repository at this point in the history
- `ophyd_async.sim.demo` -> `ophyd_async.demo`
- `ophyd_async.sim.testing` -> `ophyd_async.testing`
- `ophyd_async.*.demo` -> `ophyd_async.*.sim`
  • Loading branch information
coretl authored Dec 17, 2024
1 parent a0e1dad commit c781e27
Show file tree
Hide file tree
Showing 42 changed files with 99 additions and 109 deletions.
10 changes: 5 additions & 5 deletions docs/examples/epics_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ophyd import Component, Device, EpicsSignal, EpicsSignalRO

from ophyd_async.core import init_devices
from ophyd_async.epics import demo
from ophyd_async.epics import sim

# Create a run engine, with plotting, progressbar and transform
RE = RunEngine({}, call_returns_result=True)
Expand All @@ -19,7 +19,7 @@
register_transform("RE", prefix="<")

# Start IOC with demo pvs in subprocess
pv_prefix = demo.start_ioc_subprocess()
pv_prefix = sim.start_ioc_subprocess()


# Create ophyd devices
Expand All @@ -32,6 +32,6 @@ class OldSensor(Device):

# Create ophyd-async devices
with init_devices():
det = demo.Sensor(pv_prefix)
det_group = demo.SensorGroup(pv_prefix)
samp = demo.SampleStage(pv_prefix)
det = sim.Sensor(pv_prefix)
det_group = sim.SensorGroup(pv_prefix)
samp = sim.SampleStage(pv_prefix)
10 changes: 5 additions & 5 deletions docs/examples/tango_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import bluesky.plans as bp
from bluesky import RunEngine

from ophyd_async.tango.demo import (
from ophyd_async.tango.sim import (
DemoCounter,
DemoMover,
TangoDetector,
Expand All @@ -14,11 +14,11 @@
content = (
{
"class": DemoMover,
"devices": [{"name": "demo/motor/1"}],
"devices": [{"name": "sim/motor/1"}],
},
{
"class": DemoCounter,
"devices": [{"name": "demo/counter/1"}, {"name": "demo/counter/2"}],
"devices": [{"name": "sim/counter/1"}, {"name": "sim/counter/2"}],
},
)

Expand All @@ -30,8 +30,8 @@ async def main():
detector = TangoDetector(
trl="",
name="detector",
counters_kwargs={"prefix": "demo/counter/", "count": 2},
mover_kwargs={"trl": "demo/motor/1"},
counters_kwargs={"prefix": "sim/counter/", "count": 2},
mover_kwargs={"trl": "sim/motor/1"},
)
await detector.connect()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The two approaches now look like:

```python
class Sensor(StandardReadable, EpicsDevice):
"""A demo sensor that produces a scalar value based on X and Y Movers"""
"""A sim sensor that produces a scalar value based on X and Y Movers"""

value: A[SignalR[float], PvSuffix("Value"), Format.HINTED_SIGNAL]
mode: A[SignalRW[EnergyMode], PvSuffix("Mode"), Format.CONFIG_SIGNAL]
Expand Down
4 changes: 2 additions & 2 deletions docs/how-to/compound-devices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Assembly

Compound assemblies can be used to group Devices into larger logical Devices:

.. literalinclude:: ../../src/ophyd_async/epics/demo/_mover.py
.. literalinclude:: ../../src/ophyd_async/epics/sim/_mover.py
:pyobject: SampleStage

This applies prefixes on construction:
Expand All @@ -35,7 +35,7 @@ Grouping by Index

Sometimes, it makes sense to group devices by number, say an array of sensors:

.. literalinclude:: ../../src/ophyd_async/epics/demo/_sensor.py
.. literalinclude:: ../../src/ophyd_async/epics/sim/_sensor.py
:pyobject: SensorGroup

:class:`~ophyd-async.core.DeviceVector` allows writing maintainable, arbitrary-length device groups instead of fixed classes for each possible grouping. A :class:`~ophyd-async.core.DeviceVector` can be accessed via indices, for example: ``my_sensor_group.sensors[2]``. Here ``sensors`` is a dictionary with integer indices rather than a list so that the most semantically sensible indices may be used, the sensor group above may be 1-indexed, for example, because the sensors' datasheet calls them "sensor 1", "sensor 2" etc.
Expand Down
8 changes: 4 additions & 4 deletions docs/how-to/make-a-simple-device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To make a simple device, you need to subclass from the
other suitable Bluesky `Protocols <hardware_interface>` like
:external+bluesky:py:class:`bluesky.protocols.Movable`.

The rest of this guide will show examples from ``src/ophyd_async/epics/demo/__init__.py``
The rest of this guide will show examples from ``src/ophyd_async/epics/sim/__init__.py``

Readable
--------
Expand All @@ -22,7 +22,7 @@ For a simple :external+bluesky:py:class:`bluesky.protocols.Readable` object like
define some signals, then tell the superclass which signals should contribute to
``read()`` and ``read_configuration()``:

.. literalinclude:: ../../src/ophyd_async/epics/demo/_sensor.py
.. literalinclude:: ../../src/ophyd_async/epics/sim/_sensor.py
:pyobject: Sensor

First some Signals are constructed and stored on the Device. Each one is passed
Expand Down Expand Up @@ -54,7 +54,7 @@ Movable
For a more complicated device like a `Mover`, you can still use `StandardReadable`
and implement some addition protocols:

.. literalinclude:: ../../src/ophyd_async/epics/demo/_mover.py
.. literalinclude:: ../../src/ophyd_async/epics/sim/_mover.py
:pyobject: Mover

The ``set()`` method implements :external+bluesky:py:class:`bluesky.protocols.Movable`. This
Expand All @@ -71,7 +71,7 @@ Assembly

Compound assemblies can be used to group Devices into larger logical Devices:

.. literalinclude:: ../../src/ophyd_async/epics/demo/_mover.py
.. literalinclude:: ../../src/ophyd_async/epics/sim/_mover.py
:pyobject: SampleStage

This applies prefixes on construction:
Expand Down
10 changes: 5 additions & 5 deletions docs/how-to/write-tests-for-devices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Mock Backend

Ophyd devices initialized with a mock backend behave in a similar way to mocks, without requiring you to mock out all the dependencies and internals. The `init_devices` can initialize any number of devices, and their signals and sub-devices (recursively), with a mock backend.

.. literalinclude:: ../../tests/epics/demo/test_demo.py
.. literalinclude:: ../../tests/epics/sim/test_epics_sim.py
:pyobject: mock_sensor


Expand All @@ -37,26 +37,26 @@ Mock signals behave as simply as possible, holding a sensible default value when

In addition this example also utilizes helper functions like ``assert_reading`` and ``assert_value`` to ensure the validity of device readings and values. For more information see: :doc:`API.core<../_api/ophyd_async.core>`

.. literalinclude:: ../../tests/epics/demo/test_demo.py
.. literalinclude:: ../../tests/epics/sim/test_epics_sim.py
:pyobject: test_sensor_reading_shows_value


Given that the mock signal holds a ``unittest.mock.Mock`` object you can retrieve this object and assert that the device has been set correctly using ``get_mock_put``. You are also free to use any other behaviour that ``unittest.mock.Mock`` provides, such as in this example which sets the parent of the mock to allow ordering across signals to be asserted:

.. literalinclude:: ../../tests/epics/demo/test_demo.py
.. literalinclude:: ../../tests/epics/sim/test_epics_sim.py
:pyobject: test_retrieve_mock_and_assert

There are several other test utility functions:

Use ``callback_on_mock_put``, for hooking in logic when a mock value changes (e.g. because someone puts to it). This can be called directly, or used as a context, with the callbacks ending after exit.

.. literalinclude:: ../../tests/epics/demo/test_demo.py
.. literalinclude:: ../../tests/epics/sim/test_epics_sim.py
:pyobject: test_mover_stopped


Testing a Device in a Plan with the RunEngine
---------------------------------------------
.. literalinclude:: ../../tests/epics/demo/test_demo.py
.. literalinclude:: ../../tests/epics/sim/test_epics_sim.py
:pyobject: test_sensor_in_plan


Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/using-existing-devices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ that you can mix Ophyd and Ophyd Async devices in the same RunEngine:
:start-after: # Create ophyd devices
:end-before: # Create ophyd-async devices

Finally we create the Ophyd Async devices imported from the `epics.demo` module:
Finally we create the Ophyd Async devices imported from the `epics.sim` module:

.. literalinclude:: ../examples/epics_demo.py
:language: python
Expand Down
14 changes: 4 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,12 @@ exhaustive = true
exhaustive_ignores = ["testing", "_version", "__main__"]

[[tool.importlinter.contracts]]
name = "Testing modules"
type = "layers"
containers = ["ophyd_async"]
layers = ["testing", "core"]

[[tool.importlinter.contracts]]
name = "Testing modules are not used at runtime"
name = "Testing and sim modules are not used at runtime"
type = "forbidden"
source_modules = "ophyd_async.testing"
forbidden_modules = [
forbidden_modules = ["ophyd_async.testing", "ophyd_async.sim"]
source_modules = [
"ophyd_async.plan_stubs",
"ophyd_async.fastcs",
"ophyd_async.fast.*",
"ophyd_async.epics",
"ophyd_async.tango",
]
2 changes: 1 addition & 1 deletion src/ophyd_async/core/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class DeviceVector(MutableMapping[int, DeviceT], Device):
In the below example, foos becomes a dictionary on the parent device
at runtime, so parent.foos[2] returns a FooDevice. For example usage see
:class:`~ophyd_async.epics.demo.DynamicSensorGroup`
:class:`~ophyd_async.epics.sim.DynamicSensorGroup`
"""

def __init__(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions src/ophyd_async/sim/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from ._pattern_detector import (
DATA_PATH,
SUM_PATH,
PatternDetector,
PatternDetectorController,
PatternDetectorWriter,
PatternGenerator,
)
from ._sim_motor import SimMotor

__all__ = [
"DATA_PATH",
"SUM_PATH",
"PatternGenerator",
"PatternDetector",
"PatternDetectorController",
"PatternDetectorWriter",
"SimMotor",
]
File renamed without changes.
19 changes: 0 additions & 19 deletions src/ophyd_async/sim/demo/__init__.py

This file was deleted.

13 changes: 0 additions & 13 deletions src/ophyd_async/sim/testing/__init__.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions src/ophyd_async/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
set_mock_value,
set_mock_values,
)
from ._one_of_everything import (
ExampleEnum,
ExampleTable,
OneOfEverythingDevice,
ParentOfEverythingDevice,
)
from ._wait_for_pending import wait_for_pending_wakeups

__all__ = [
Expand All @@ -30,4 +36,8 @@
"set_mock_value",
"set_mock_values",
"wait_for_pending_wakeups",
"ExampleEnum",
"ExampleTable",
"OneOfEverythingDevice",
"ParentOfEverythingDevice",
]
2 changes: 1 addition & 1 deletion tests/core/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
init_devices,
)
from ophyd_async.epics import adsimdetector
from ophyd_async.sim.demo import SimMotor
from ophyd_async.sim import SimMotor


async def make_detector(prefix: str, name: str, tmp_path: Path):
Expand Down
Loading

0 comments on commit c781e27

Please sign in to comment.