Open cartermak opened 7 months ago
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()
Currently, the
plans
command has sub-commands forcreate-config
andupdate-config
. It would be helpful to create aconfig
sub-command ofplans
with its own CRUD sub-commands (or, more likely, just CRU).