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

Separate sim config commands #106

Open
cartermak opened this issue Dec 19, 2023 · 1 comment
Open

Separate sim config commands #106

cartermak opened this issue Dec 19, 2023 · 1 comment
Labels
breaking change Proposal or code break existing interfaces. enhancement New/improved features and capabilities
Milestone

Comments

@cartermak
Copy link
Member

Currently, the plans command has sub-commands for create-config and update-config. It would be helpful to create a config sub-command of plans with its own CRUD sub-commands (or, more likely, just CRU).

@cartermak
Copy link
Member Author

Quick script to get the sim config:

"""
Get the full configuration used for a given simulation.

This script will load the current active Aerie-CLI session.
"""

import json
import argparse
from pathlib import Path

from aerie_cli.utils.sessions import get_active_session_client

GET_SIM_CONFIG_QUERY = """
query GetSimulationConfiguration($sim_dataset_id: Int!) {
  simulation_dataset_by_pk(id: $sim_dataset_id) {
    arguments
  }
}
"""

GET_EFFECTIVE_CONFIG_QUERY = """
query GetEffectiveModelArguments($model_id: ID!, $arguments: ModelArguments!) {
  effectiveModelArguments: getModelEffectiveArguments(missionModelId: $model_id, modelArguments: $arguments) {
    arguments
    errors
    success
  }
}
"""


def main():

    # Parse command-line arguments for inputs
    parser = argparse.ArgumentParser()
    parser.add_argument("-s", "--sim-dataset-id", type=int,
                        help="ID of simulation dataset")
    parser.add_argument("-o", "--output", type=Path, help="Output file")
    args = parser.parse_args()

    # Get active session from Aerie-CLI (same as any Aerie-CLI command would use)
    client = get_active_session_client()

    # Get the model ID for this simulation dataset (used later)
    plan_id = client.get_plan_id_by_sim_id(args.sim_dataset_id)
    all_plans = client.list_all_activity_plans()
    model_id = next(
        iter([p.model_id for p in all_plans if p.id == plan_id]), None)
    if model_id is None:
        raise RuntimeError("Failed to get model ID")

    # First, get the arguments as stored in the database. This excludes defaults from the mission model.
    arguments = client.aerie_host.post_to_graphql(
        GET_SIM_CONFIG_QUERY, sim_dataset_id=args.sim_dataset_id)["arguments"]

    # Next, get the full effective arguments, including mission model defaults.
    resp = client.aerie_host.post_to_graphql(
        GET_EFFECTIVE_CONFIG_QUERY, model_id=model_id, arguments=arguments)

    if not resp["success"]:
        raise RuntimeError("Failed to get effective arguments")

    # Write output JSON file
    with open(args.output, "w") as fid:
        json.dump(resp["arguments"], fid, indent=2)


if __name__ == "__main__":
    main()

@cartermak cartermak added this to the v3 milestone Jan 29, 2024
@cartermak cartermak added enhancement New/improved features and capabilities breaking change Proposal or code break existing interfaces. labels Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Proposal or code break existing interfaces. enhancement New/improved features and capabilities
Projects
None yet
Development

No branches or pull requests

1 participant