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 37 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
16 changes: 9 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ to the input of **counter_sink**.

.. code-block:: yaml

- 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:
component: counter
port: _value


This file is executed to run the simulation.
Expand Down
52 changes: 30 additions & 22 deletions docs/user/explanations/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,36 @@ 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:
component: random_trampoline
port: output
components:
- type: tickit.devices.sink.Sink
name: internal_sink
inputs:
sink_1:
component: external
port: input_1
- type: examples.devices.remote_controlled.RemoteControlled
name: internal_tcp_controlled
inputs: {}
expose:
output_1:
component: internal_tcp_controlled
port: observed
- type: tickit.devices.sink.Sink
name: external_sink
inputs:
sink_1:
component: internal_tickit
port: output_1

(See `SystemSimulationComponent`.)

Expand Down
18 changes: 10 additions & 8 deletions docs/user/explanations/wiring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ 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:
component: rand_tramp
port: output
34 changes: 19 additions & 15 deletions docs/user/tutorials/create-a-device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ if the device requires any adapters to control it externally.

.. code-block:: python

from dataclasses import dataclass
from tickit.utils.compat.pydantic_compat import pydantic_dataclass

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


@dataclass
@pydantic_dataclass
class Amplifier(ComponentConfig):
initial_amplification: float

Expand All @@ -147,19 +147,23 @@ 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:
component: source
port: value
initial_amplification: 2.0
- type: tickit.devices.sink.Sink
name: sink
inputs:
input:
component: amp
port: amplified_signal


Where in ``amp.Amplifier`` ``amp`` is the name of the ``.py`` file the amplifier
Expand Down
22 changes: 12 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,25 @@ 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:
component rand_tramp
port: 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_dataclass
class Amplifier(ComponentConfig):
initial_amplification: int

Expand Down
30 changes: 17 additions & 13 deletions examples/configs/amplifier.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
- 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:
component: source
port: value
initial_amplification: 2
- type: tickit.devices.sink.Sink
name: sink
inputs:
input:
component: amp
port: amplified_signal
16 changes: 9 additions & 7 deletions examples/configs/counter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
- 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:
component: counter
port: _value
4 changes: 3 additions & 1 deletion examples/configs/http-and-zeromq-devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
- examples.devices.zeromq_push_device.ExampleZeroMqPusher:
DiamondJoseph marked this conversation as resolved.
Show resolved Hide resolved
name: zeromq-pusher
inputs:
updates: http-device:updates
updates:
component: http-device
port: updates
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
52 changes: 30 additions & 22 deletions examples/configs/nested.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
- 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:
component: random_trampoline
port: output
components:
- type: tickit.devices.sink.Sink
name: internal_sink
inputs:
sink_1:
component: external
port: input_1
- type: examples.devices.remote_controlled.RemoteControlled
name: internal_tcp_controlled
inputs: {}
expose:
output_1:
component: internal_tcp_controlled
port: observed
- type: tickit.devices.sink.Sink
name: external_sink
inputs:
sink_1:
component: internal_tickit
port: output_1
32 changes: 18 additions & 14 deletions examples/configs/shutter.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
- 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:
component: source
port: value
default_position: 0.2
initial_position: 0.24
- type: tickit.devices.sink.Sink
name: sink
inputs:
flux:
component: shutter
port: flux
18 changes: 10 additions & 8 deletions examples/configs/sunk-tcp.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
- 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:
component: tcp_contr
port: observed
DiamondJoseph marked this conversation as resolved.
Show resolved Hide resolved
Loading