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

Replace APISchema Serialization with Pydantic 1.0 #154

Merged
merged 46 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c528d60
Replace ApiSchema with Pydantic v1 validation
DiamondJoseph Jul 14, 2023
613a0ec
Replace TypedDict with Type
DiamondJoseph Jul 14, 2023
e5023ea
Working non-nested version
DiamondJoseph Jul 14, 2023
c06492d
linting
DiamondJoseph Jul 14, 2023
98d95da
Remove outdated tests
DiamondJoseph Jul 14, 2023
5964d01
Move loading into annotation
DiamondJoseph Jul 14, 2023
9ffacd7
Changes
DiamondJoseph Jul 14, 2023
d190fc7
Make devices a module
DiamondJoseph Jul 14, 2023
950ccc4
Adjust tests
DiamondJoseph Jul 14, 2023
1478dc7
Linting
DiamondJoseph Jul 14, 2023
e2bd00d
Mypy
DiamondJoseph Jul 14, 2023
7d2517e
Remove duplicate inputs on system simulation, and re-use validation f…
DiamondJoseph Jul 14, 2023
bdda7bc
Remove StrictConfig
DiamondJoseph Jul 14, 2023
9b82b32
Merge branch 'master' into pydantic1
DiamondJoseph Jul 14, 2023
7c6be12
Ensure consistency with Pydantic dataclass usage
DiamondJoseph Jul 14, 2023
acbb2f6
Update docs for TypedDict type and discriminator field
DiamondJoseph Jul 14, 2023
3df8ee3
Update src for TypedDict type and discriminator field
DiamondJoseph Jul 14, 2023
7db3cae
Merge branch 'pydantic0' of github.com:dls-controls/tickit into pydan…
DiamondJoseph Jul 14, 2023
27f91ab
Use parse_obj_as(List)
DiamondJoseph Jul 14, 2023
625fda3
Revert TypedDict type change (not required, not serialising device ty…
DiamondJoseph Jul 18, 2023
69f1d30
Allow for Pydantic 1 or Pydantic 2
DiamondJoseph Jul 18, 2023
3605a95
Revert changes to mock config parsing
DiamondJoseph Jul 18, 2023
9b16ee6
Linting and spaces
DiamondJoseph Jul 18, 2023
2f06f68
Adjust versioned import
DiamondJoseph Jul 18, 2023
4058337
Adjust versioned import
DiamondJoseph Jul 18, 2023
93eb948
Mypy
DiamondJoseph Jul 18, 2023
26c19aa
Merge remote-tracking branch 'origin/pydantic1' into pydantic1
DiamondJoseph Jul 18, 2023
f8566c7
Handle single type for 3.9 annotations
DiamondJoseph Jul 18, 2023
6a0b4f9
Remove method
DiamondJoseph Jul 18, 2023
4173d07
Move validator to ComponentPort root_validator
DiamondJoseph Jul 18, 2023
ed012a9
Linting
DiamondJoseph Jul 19, 2023
11e42d4
Refactor conditional imports for Pydantic versions
DiamondJoseph Jul 19, 2023
fe11446
Move pydantic_compat out of typing_compat
DiamondJoseph Jul 19, 2023
3e2d6e6
Merge master into Pydantic1
DiamondJoseph Jul 19, 2023
66ec841
Refactor new config
DiamondJoseph Jul 19, 2023
06fa087
Refactor config to explictly map inputs to ComponentPort type
DiamondJoseph Jul 19, 2023
39888a2
Refactor config to explictly map inputs to ComponentPort type
DiamondJoseph Jul 19, 2023
dbaa420
Correct configs and ensure byte format deserialisation
DiamondJoseph Jul 20, 2023
fe780fc
Remove Pydantic_Compat and support only Pydantic >=2
DiamondJoseph Jul 20, 2023
d6321ed
Ensure byte_format serialises and deserialises correctly.
DiamondJoseph Jul 20, 2023
f9e1866
Rename and refactor configurable
DiamondJoseph Jul 20, 2023
aa0ceec
Linting
DiamondJoseph Jul 20, 2023
077234b
Remove Build directory
DiamondJoseph Jul 20, 2023
f044aa1
Linting
DiamondJoseph Jul 20, 2023
0432541
Linting
DiamondJoseph Jul 20, 2023
38e6e8a
docs fixes
DiamondJoseph Jul 20, 2023
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
44 changes: 22 additions & 22 deletions docs/user/explanations/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ the master scheduler's wiring is correct, for example:

.. code-block:: yaml

- examples.devices.trampoline.RandomTrampoline:
name: random_trampoline
inputs: {}
callback_period: 10000000000
- tickit.core.components.system_simulation.SystemSimulation:
name: internal_tickit
inputs:
input_1: random_trampoline:output
components:
- tickit.devices.sink.Sink:
name: internal_sink
inputs:
sink_1: external:input_1
- examples.devices.remote_controlled.RemoteControlled:
name: internal_tcp_controlled
inputs: {}
expose:
output_1: internal_tcp_controlled:observed
- tickit.devices.sink.Sink:
name: external_sink
inputs:
sink_1: internal_tickit:output_1
- type: examples.devices.trampoline.RandomTrampoline
name: random_trampoline
inputs: {}
callback_period: 10000000000
- type: tickit.core.components.system_simulation.SystemSimulation
name: internal_tickit
inputs:
input_1: random_trampoline:output
components:
- type: tickit.devices.sink.Sink
name: internal_sink
inputs:
sink_1: external:input_1
- type: examples.devices.remote_controlled.RemoteControlled
name: internal_tcp_controlled
inputs: {}
expose:
output_1: internal_tcp_controlled:observed
- type: tickit.devices.sink.Sink
name: external_sink
inputs:
sink_1: internal_tickit:output_1

(See `SystemSimulationComponent`.)

Expand Down
4 changes: 2 additions & 2 deletions docs/user/explanations/devices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ values and requests to be called back for an update sometime later.
"""A trivial toy device which produced a random output and requests a callback."""

#: An empty typed mapping of device inputs
Inputs: TypedDict = TypedDict("Inputs", {})
Inputs: type = TypedDict("Inputs", {})
#: A typed mapping containing the 'output' output value
Outputs: TypedDict = TypedDict("Outputs", {"output": int})
Outputs: type = TypedDict("Outputs", {"output": int})

def __init__(self, callback_period: int = int(1e9)) -> None:
self.callback_period = SimTime(callback_period)
Expand Down
16 changes: 8 additions & 8 deletions docs/user/explanations/wiring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ which outputs random numbers, and a sink taking that output as an input:

.. code-block:: yaml

- examples.devices.trampoline.RandomTrampoline:
name: rand_tramp
inputs: {}
callback_period: 1000000000
- tickit.devices.sink.Sink:
name: tramp_sink
inputs:
input: rand_tramp:output
- type: examples.devices.trampoline.RandomTrampoline
name: rand_tramp
inputs: {}
callback_period: 1000000000
- type: tickit.devices.sink.Sink
name: tramp_sink
inputs:
input: rand_tramp:output
42 changes: 21 additions & 21 deletions docs/user/tutorials/create-a-device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ maps as members. As such we shall put in the following boilerplate.

class AmplifierDevice(Device):

Inputs: TypedDict = TypedDict("Inputs", {})
Outputs: TypedDict = TypedDict("Outputs", {})
Inputs: type = TypedDict("Inputs", {})
Outputs: type = TypedDict("Outputs", {})

def __init__(self) -> None:

Expand All @@ -59,8 +59,8 @@ here.

class AmplifierDevice(Device):

Inputs: TypedDict = TypedDict("Inputs", {})
Outputs: TypedDict = TypedDict("Outputs", {})
Inputs: type = TypedDict("Inputs", {})
Outputs: type = TypedDict("Outputs", {})

def __init__(self, initial_amplification: float = 2) -> None:
self.amplification = initial_amplification
Expand Down Expand Up @@ -95,8 +95,8 @@ we define our inputs and outputs in the maps, and the line of logic in the ``upd

class AmplifierDevice(Device):

Inputs: TypedDict = TypedDict("Inputs", {"initial_signal":float})
Outputs: TypedDict = TypedDict("Outputs", {"amplified_signal":float})
Inputs: type = TypedDict("Inputs", {"initial_signal":float})
Outputs: type = TypedDict("Outputs", {"amplified_signal":float})

def __init__(self, initial_amplification: float = 2.0) -> None:
self.amplification = initial_amplification
Expand All @@ -118,13 +118,13 @@ if the device requires any adapters to control it externally.

.. code-block:: python

from dataclasses import dataclass
import pydantic.v1.dataclasses

from tickit.core.components.component import Component, ComponentConfig
from tickit.core.components.device_simulation import DeviceSimulation


@dataclass
@pydantic.v1.dataclasses.dataclass
class Amplifier(ComponentConfig):
initial_amplification: float

Expand All @@ -147,19 +147,19 @@ and a `Sink`, named sink, which will receive the amplified signal.

.. code-block:: yaml

- tickit.devices.source.Source:
name: source
inputs: {}
value: 10.0
- amp.Amplifier:
name: amp
inputs:
initial_signal: source:value
initial_amplification: 2.0
- tickit.devices.sink.Sink:
name: sink
inputs:
input: amp:amplified_signal
- type: tickit.devices.source.Source
name: source
inputs: {}
value: 10.0
- type: amp.Amplifier
name: amp
inputs:
initial_signal: source:value
initial_amplification: 2.0
- type: tickit.devices.sink.Sink
name: sink
inputs:
input: amp:amplified_signal


Where in ``amp.Amplifier`` ``amp`` is the name of the ``.py`` file the amplifier
Expand Down
20 changes: 10 additions & 10 deletions docs/user/tutorials/creating-a-simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ we may extend our config, as:

.. code-block:: yaml

- examples.devices.trampoline.RandomTrampoline:
name: rand_tramp
inputs: {}
- type: examples.devices.trampoline.RandomTrampoline
name: rand_tramp
inputs: {}

We will now add a `Sink` device. This device will be named ``tramp_sink``, will have
no adapters but will take the ``output`` value of ``rand_tramp`` as ``input``. As
such we may extend our config, as:

.. code-block:: yaml

- examples.devices.trampoline.RandomTrampoline:
name: rand_tramp
inputs: {}
- tickit.devices.sink.Sink:
name: tramp_sink
inputs:
input: rand_tramp:output
- type: examples.devices.trampoline.RandomTrampoline
name: rand_tramp
inputs: {}
- type: tickit.devices.sink.Sink
name: tramp_sink
inputs:
input: rand_tramp:output

Running the Simulation
----------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/user/tutorials/use-composed-adapter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ our amplifier `ComponentConfig`. To do this we simply add it to the arguments of

.. code-block:: python

@dataclass
@pydantic.v1.dataclasses.dataclass
class Amplifier(ComponentConfig):
initial_amplification: int

Expand Down
26 changes: 13 additions & 13 deletions examples/configs/amplifier.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
- tickit.devices.source.Source:
name: source
inputs: {}
value: 10.0
- examples.devices.amplifier.Amplifier:
name: amp
inputs:
initial_signal: source:value
initial_amplification: 2
- tickit.devices.sink.Sink:
name: sink
inputs:
input: amp:amplified_signal
- type: tickit.devices.source.Source
name: source
inputs: {}
value: 10.0
- type: examples.devices.amplifier.Amplifier
name: amp
inputs:
initial_signal: source:value
initial_amplification: 2
- type: tickit.devices.sink.Sink
name: sink
inputs:
input: amp:amplified_signal
14 changes: 7 additions & 7 deletions examples/configs/counter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- examples.devices.counter.Counter:
name: counter
inputs: {}
- tickit.devices.sink.Sink:
name: counter_sink
inputs:
input: counter:_value
- type: examples.devices.counter.Counter
name: counter
inputs: {}
- type: tickit.devices.sink.Sink
name: counter_sink
inputs:
input: counter:_value
6 changes: 3 additions & 3 deletions examples/configs/http-device.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- examples.devices.http_device.ExampleHttpDevice:
name: http-device
inputs: {}
- type: examples.devices.http_device.ExampleHttpDevice:
name: http-device
inputs: {}
12 changes: 6 additions & 6 deletions examples/configs/isolated-device.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- examples.devices.isolated_device.IsolatedBox:
name: MrBox
inputs: {}
initial_value: 2
ioc_name: ISOLATED_BOX
port: 25561
- type: examples.devices.isolated_device.IsolatedBox
name: MrBox
inputs: {}
initial_value: 2
ioc_name: ISOLATED_BOX
port: 25561
44 changes: 22 additions & 22 deletions examples/configs/nested.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
- examples.devices.trampoline.RandomTrampoline:
name: random_trampoline
inputs: {}
callback_period: 10000000000
- tickit.core.components.system_simulation.SystemSimulation:
name: internal_tickit
inputs:
input_1: random_trampoline:output
components:
- tickit.devices.sink.Sink:
name: internal_sink
inputs:
sink_1: external:input_1
- examples.devices.remote_controlled.RemoteControlled:
name: internal_tcp_controlled
inputs: {}
expose:
output_1: internal_tcp_controlled:observed
- tickit.devices.sink.Sink:
name: external_sink
inputs:
sink_1: internal_tickit:output_1
- type: examples.devices.trampoline.RandomTrampoline
name: random_trampoline
inputs: {}
callback_period: 10000000000
- type: tickit.core.components.system_simulation.SystemSimulation
name: internal_tickit
inputs:
input_1: random_trampoline:output
components:
- type: tickit.devices.sink.Sink
name: internal_sink
inputs:
sink_1: external:input_1
- type: examples.devices.remote_controlled.RemoteControlled
name: internal_tcp_controlled
inputs: {}
expose:
output_1: internal_tcp_controlled:observed
- type: tickit.devices.sink.Sink
name: external_sink
inputs:
sink_1: internal_tickit:output_1
28 changes: 14 additions & 14 deletions examples/configs/shutter.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
- tickit.devices.source.Source:
name: source
inputs: {}
value: 42.0
- examples.devices.shutter.Shutter:
name: shutter
inputs:
flux: source:value
default_position: 0.2
initial_position: 0.24
- tickit.devices.sink.Sink:
name: sink
inputs:
flux: shutter:flux
- type: tickit.devices.source.Source
name: source
inputs: {}
value: 42.0
- type: examples.devices.shutter.Shutter
name: shutter
inputs:
flux: source:value
default_position: 0.2
initial_position: 0.24
- type: tickit.devices.sink.Sink
name: sink
inputs:
flux: shutter:flux
16 changes: 8 additions & 8 deletions examples/configs/sunk-tcp.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- examples.devices.remote_controlled.RemoteControlled:
name: tcp_contr
inputs: {}
format: "%b\r\n"
- tickit.devices.sink.Sink:
name: contr_sink
inputs:
input: tcp_contr:observed
- type: examples.devices.remote_controlled.RemoteControlled
name: tcp_contr
inputs: {}
format: "%b\r\n"
- type: tickit.devices.sink.Sink
name: contr_sink
inputs:
input: tcp_contr:observed
16 changes: 8 additions & 8 deletions examples/configs/sunk-trampoline.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- examples.devices.trampoline.RandomTrampoline:
name: rand_tramp
inputs: {}
callback_period: 1000000000
- tickit.devices.sink.Sink:
name: tramp_sink
inputs:
input: rand_tramp:output
- type: examples.devices.trampoline.RandomTrampoline
name: rand_tramp
inputs: {}
callback_period: 1000000000
- type: tickit.devices.sink.Sink
name: tramp_sink
inputs:
input: rand_tramp:output
Loading