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

Support parallel connect #440

Open
coretl opened this issue Apr 29, 2024 · 11 comments
Open

Support parallel connect #440

coretl opened this issue Apr 29, 2024 · 11 comments
Labels
devices connection enhancement New feature or request python Pull requests that update Python code

Comments

@coretl
Copy link
Contributor

coretl commented Apr 29, 2024

DiamondLightSource/dodal#415 (comment) summarizes a discussion on Device connection.
bluesky/ophyd-async#265 will implement the ophyd-async supporting features of idempotent connect.
DiamondLightSource/dodal#483 will implement introspectable device factories.

The strategy we would like for blueapi is:

  • Import the dodal.beamlines.<bl> module
  • Call dodal.beamlines.beamline_utils.get_device_factories() to get all the device factories and whether they are lazy or not
  • Create devices using all the factories
  • For the non-lazy factories kick off connection in a background task (parallel to start off, revisit this if there are performance problems)
  • Allow plans to be run
  • When a plan is run, call ophyd_async.plan_stubs.ensure_connected(*devices) on all plan args and default args that are devices

Time sensitivity

Only needed when a beamline starts having so many devices that the startup connection time is delayed enough to be problematic
#440 (comment)

joeshannon added a commit that referenced this issue May 13, 2024
The device connection is now handled by device_instantiation in dodal.
This function also provides the option on whether to wait for
connection, so it is not needed here too.

Additionally it can lead to undefined (currently) behaviour if the
device is initially created with fake_with_ophyd_sim = True but then
later connected again by blueapi with fake_with_ophyd_sim = False.

This also leaves the sim property on BlueskyContext redundant so
that is removed too.

For full customisation and flexibility of lazy connect we need #440.

Fixes #461.
@stan-dot stan-dot self-assigned this Jun 5, 2024
@stan-dot stan-dot linked a pull request Jun 20, 2024 that will close this issue
@stan-dot
Copy link
Contributor

    def with_dodal_module(self, module: ModuleType, **kwargs) -> None:
        devices, exceptions = make_all_devices(module, **kwargs)

        for device in devices.values():
            self.device(device)

        # If exceptions have occurred, we log them but we do not make blueapi
        # fall over
        if len(exceptions) > 0:
            LOGGER.warning(
                f"{len(exceptions)} exceptions occurred while instantiating devices"
            )
            LOGGER.exception(NotConnected(exceptions))

change the call to make_all_devices inside context.py

@stan-dot
Copy link
Contributor

not sure if we should support the old and new instantiation behaviour or make it behind a flag and go beamline-by-beamline

@callumforrester
Copy link
Contributor

@stan-dot I would favour supporting both, deprecating one and making issues to migrate as-and-when. Migrating beamline-by-beamline is still ideal but not mandated.

@stan-dot
Copy link
Contributor

same

@stan-dot stan-dot added enhancement New feature or request python Pull requests that update Python code devices connection labels Sep 9, 2024
@stan-dot
Copy link
Contributor

@callumforrester now that isolated_device_factory got merged we can presumably resume work on this. At the moment we could only lazy connect for i22, do you have any amendments to the strategy since the issue definition in April?

@callumforrester
Copy link
Contributor

In general I am against lazy connection unless it is needed for performance reasons. If a device isn't available, the earlier you know the better!

@stan-dot
Copy link
Contributor

ok but we still want the parallel connection, right?

@callumforrester
Copy link
Contributor

We do, also isolated_device_factory has now been reverted

@stan-dot stan-dot changed the title Support parallel and lazy connect Support parallel connect Oct 29, 2024
@stan-dot
Copy link
Contributor

tracking the location of the desired change

# context.py:115
 def with_dodal_module(self, module: ModuleType, **kwargs) -> None:
        devices, exceptions = make_all_devices(module, **kwargs)

        for device in devices.values():
            self.device(device)

        # If exceptions have occurred, we log them but we do not make blueapi
        # fall over
        if len(exceptions) > 0:
            LOGGER.warning(
                f"{len(exceptions)} exceptions occurred while instantiating devices"
            )
            LOGGER.exception(NotConnected(exceptions))

and after device registration step presumably

@stan-dot
Copy link
Contributor

@callumforrester is the location of change comment correct?

still I assume that to support parallel connect we'll need to wait for the bluesky / dodal / device factory shakeup to be resolved, so some weeks, right?

@callumforrester
Copy link
Contributor

@stan-dot I'm unsure without further investigation. Yes it depends on the factory shakeup. However even then it is not a high priority. The work so far has to make sure we don't design parallel connect out when we need it, which will happen when beamlines start having many devices and slowing down blueapi's startup time. At that point we can prioritise this issue.

@stan-dot stan-dot removed their assignment Nov 1, 2024
@stan-dot stan-dot closed this as completed Nov 1, 2024
@stan-dot stan-dot reopened this Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devices connection enhancement New feature or request python Pull requests that update Python code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants