Skip to content

Add env files to run sim#145

Merged
fredericpoitevin merged 3 commits intopcdshub:run23from
pluflou:add-env-files
Apr 21, 2025
Merged

Add env files to run sim#145
fredericpoitevin merged 3 commits intopcdshub:run23from
pluflou:add-env-files

Conversation

@pluflou
Copy link
Collaborator

@pluflou pluflou commented Apr 8, 2025

Description

This PR adds environment files for conda and pixi to allow devs to easily set up the packages needed to run the beam alignment optimization simulation. The pixi.toml file is at the root of the repo and has a "optimize" environment (that's also currently the default since we have no other "base" env for the repo).

To run

You can create a conda environment from this file with conda env create -f /path/to/environment.yml then run the sim with python -m mfx.optimize.xopt_scans. Or you can run directly using the pixi environment, e.g. pixi run -e optimize python -m mfx.optimize.xopt_scans.

@pluflou pluflou marked this pull request as ready for review April 8, 2025 18:22
@pluflou pluflou requested a review from jennmald April 8, 2025 18:26
@fredericpoitevin
Copy link
Collaborator

fredericpoitevin commented Apr 9, 2025

I ended up installing micromamba on my Mac (M2 Pro).

FYI I got this:

...
Transaction finished


To activate this environment, use:

    micromamba activate mfx-opt-env

Or to execute a single command in this environment, use:

    micromamba run -n mfx-opt-env mycommand

warning  libmamba You are using 'pip' as an additional package manager.
    Be aware that packages installed with 'pip' are managed independently from 'conda-forge' channel.

Installing pip packages: lcls-tools @ git+https://github.com/slaclab/lcls-tools.git, pcdsdevices @ git+https://github.com/pcdshub/pcdsdevices.git
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
sirepo-bluesky 0.4.0 requires inflection, which is not installed.
sirepo-bluesky 0.4.0 requires pyqt5<5.12,>=5.9, which is not installed.
sirepo-bluesky 0.4.0 requires scikit-image, which is not installed.
bloptools 0.1.0 requires ortools, which is not installed.

Working on a fix but adding inflection ortools pyqt5<5.12,>=5.9 to pip and scikit-image did not work:

Updating pip packages: inflection, ortools, pyqt5<5.12,>=5.9, lcls-tools @ git+https://github.com/slaclab/lcls-tools.git, pcdsdevices @ git+https://github.com/pcdshub/pcdsdevices.git
/Users/fpoitevi/micromamba/envs/mfx-opt-env/etc/conda/deactivate.d/happi.sh: line 13: complete: happi: no completion specification
ERROR: Could not find a version that satisfies the requirement pyqt5<5.12,>=5.9 (from versions: 5.14.0, 5.14.1, 5.14.2, 5.15.0, 5.15.1, 5.15.2, 5.15.3, 5.15.4, 5.15.5, 5.15.6, 5.15.7, 5.15.8, 5.15.9, 5.15.10, 5.15.11)
ERROR: No matching distribution found for pyqt5<5.12,>=5.9
critical libmamba pip failed to update packages

@pluflou
Copy link
Collaborator Author

pluflou commented Apr 9, 2025

@fredericpoitevin I just tried it on my new Mac with M3, and I had no issues. I used Conda version 25.1.1. I am not familiar with Micromamba so I won't try to debug that for you, but I suggested you try using Conda version 23.10 and up which ships with the libmamba solver as the default (or, more ideally, the latest one) and let me know how that goes.

Copy link
Collaborator

@fredericpoitevin fredericpoitevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pluflou ! It's great to be able to do this on my laptop!
image

The reason I went to micromamba initially was that updating my miniconda from 23.7 to above 23.10 was taking too long so I looked for another option and picked that one. In the end, I just reinstalled miniconda3 from scratch and it worked, thanks for the advice.

I did not try pixi yet. Maybe another day.

A few observations that are not related to this PR directly but that I don't want to forget:

  • python -m mfx.optimize.xopt_scans worked for me but the plots were not displayed.
  • ipython -i mfx/optimize/xopt_scans.py did not work for me:
(mfx-opt-env) [fpoitevi@PC101094 mfx]$ ipython -i mfx/optimize/xopt_scans.py
Python 3.12.9 | packaged by conda-forge | (main, Mar  4 2025, 22:44:42) [Clang 18.1.8 ]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.1.0 -- An enhanced Interactive Python. Type '?' for help.
Tip: You can find how to type a Unicode symbol by back-completing it, eg `\Ⅷ<tab>` will expand to `\ROMAN NUMERAL EIGHT`.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
File ~/Projects/mfx/mfx/optimize/xopt_scans.py:15
     12 from lcls_tools.common.frontend.plotting.image import plot_image_projection_fit
     13 from lcls_tools.common.image.fit import ImageProjectionFit
---> 15 from .mirror_hw import (
     16     XCS_YAG_XPOS,
     17     DG1_WAVE8_XPOS,
     18     DG1_YAG_XPOS,
     19     DG2_WAVE8_XPOS,
     20     DG2_YAG_XPOS,
     21     IP_YAG_XPOS,
     22     MIRROR_NOMINAL,
     23     init_devices,
     24     sim_devices,
     25     YAG_CENTROID_X_MIN_MAX,
     26     YAG_CENTROID_Y_MIN_MAX,
     27     WAVE8_CENTROID_X_MIN_MAX,
     28     WAVE8_CENTROID_Y_MIN_MAX
     29 )
     32 def get_vocs(
     33     mirror_nominal: float = MIRROR_NOMINAL,
     34     search_delta: float = 5,
   (...)     43     centroid_y_max: float = None,
     44 ) -> VOCS:
     45     constrants = {}

ImportError: attempted relative import with no known parent package

@pluflou
Copy link
Collaborator Author

pluflou commented Apr 9, 2025

Great that it worked! Yes I noticed those things too. I think those are more of a local setup thing, but we can change some things in the code to make it less work for users to set up and run if that's desired. @fredericpoitevin should we create an issue for those two things? maybe even just updating the docs on how to run is enough.

@fredericpoitevin
Copy link
Collaborator

I think reporting this "bug" as an issue would be useful.

Copy link
Collaborator

@thopkins32 thopkins32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pixi worked for me after adding the platforms. Although I had to be at the root of the repository and do

pixi run --manifest-path mfx/optimize/pixi.toml python -m mfx.optimize.xopt_scans

Since this is meant to be run from the root of the repository, I think the pixi.toml file should be there instead of in mfx/optimize. You can set up Pixi environments that have specific dependencies as described here: https://pixi.sh/latest/workspace/multi_environment/

For example, the default environment you have set up currently could be the "optimize" environment in the repo-wide Pixi configuration. With the environment configured, the command (I think) would be

pixi run -e optimize python -m mfx.optimize.xopt_scans

Co-authored-by: Thomas Hopkins <thomashopkins000@gmail.com>
@jennmald
Copy link
Collaborator

I had the same issues as Fred, otherwise looks great to me!

@pluflou
Copy link
Collaborator Author

pluflou commented Apr 16, 2025

@fredericpoitevin @thomashopkins32 I updated the pixi.toml to have an env called "optimize" (it is also currently the default) and moved it to the root of the repo. I adjusted the PR description to reflect the changes. Do we want to document how to use these elsewhere? Perhaps the main README.md? Otherwise, the PR is ready for final review/merge.

@fredericpoitevin
Copy link
Collaborator

@fredericpoitevin @thomashopkins32 I updated the pixi.toml to have an env called "optimize" (it is also currently the default) and moved it to the root of the repo. I adjusted the PR description to reflect the changes. Do we want to document how to use these elsewhere? Perhaps the main README.md? Otherwise, the PR is ready for final review/merge.

Yes I think documenting this briefly in the main README.md would be good and then we can merge?

@fredericpoitevin fredericpoitevin added the automfx Adds to the AutoMFX Project label Apr 19, 2025
@github-project-automation github-project-automation bot moved this to Todo in AutoMFX Apr 19, 2025
@fredericpoitevin fredericpoitevin added this to the UX milestone Apr 19, 2025
@fredericpoitevin fredericpoitevin moved this from Todo to In Progress in AutoMFX Apr 19, 2025
@fredericpoitevin
Copy link
Collaborator

@pluflou - in case you'd like to merge this and work on the README.md afterwards, maybe you could do that in #162 ?

@pluflou
Copy link
Collaborator Author

pluflou commented Apr 21, 2025

@fredericpoitevin sure, that works for me.

@fredericpoitevin fredericpoitevin merged commit c9082e4 into pcdshub:run23 Apr 21, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in AutoMFX Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automfx Adds to the AutoMFX Project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants