Skip to content

Conversation

@andgoldschmidt
Copy link
Member

The purpose of this PR is to eliminate broadcasting in trajectory initialization by using the NamedTrajectories merge call, see harmoniqs/NamedTrajectories.jl#54

The price to pay is some copying.

The benefit is that this puts the burden of initialization for problems like direct sums and sampling onto the problem template. It forces the problem template to be aware of naming, which is good for programming at the level of problem templates.

For example, a clean loop for setting up a sampling problem with a lot of complexity like separate goals, separate systems, and so on:

    # Trajectory
    state_names = [
        Symbol(string(state_name, "_system_", label)) for label  1:length(systems)
    ]

    if !isnothing(init_trajectory)
        traj = init_trajectory
    else
        trajs = map(zip(systems, operators, state_names)) do (sys, op, s)
            initialize_trajectory(
                op,
                T,
                Δt,
                length(sys.G_drives),
                (a_bounds, da_bounds, dda_bounds);
                state_name=s,
                control_name=control_name,
                timestep_name=timestep_name,
                free_time=piccolo_options.free_time,
                Δt_bounds=(Δt_min, Δt_max),
                geodesic=piccolo_options.geodesic,
                bound_state=piccolo_options.bound_state,
                a_guess=a_guess,
                system=sys,
                rollout_integrator=piccolo_options.rollout_integrator,
            )
        end

        traj = merge(
            trajs, 
            merge_names=(; a=1, da=1, dda=1, Δt=1),
            free_time=piccolo_options.free_time
        )
    end    

    control_names = [
        name for name  traj.names
        if endswith(string(name), string(control_name))
    ]

@andgoldschmidt andgoldschmidt merged commit 04b2f04 into main Nov 15, 2024
3 checks passed
@andgoldschmidt andgoldschmidt deleted the feature/merge-trajectories branch November 15, 2024 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants