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

feat: Python class meta-programming for State construction #244

Merged
merged 7 commits into from
Oct 13, 2023

Conversation

kyle-cochran
Copy link
Contributor

@kyle-cochran kyle-cochran commented Oct 12, 2023

This MR is some Python-only syntactic sugar on top of the State Builder concept which allows for some nice syntax:

MySuperFunState: type = State.template(
    frame,
    [CartesianPosition.default(), CartesianVelocity.default()],
)

states: MySuperFunState = [
    MySuperFunState(instant,coords) for instant,coords in zip(instants, coordinates)
]

The output StateTypeX classes are polymorphic to State and so can be used anywhere a State can.
This example is 100% equivalent to using a builder and is just a syntax alternative.

(other meta-programming features like auto-assigning state.mass to get the mass value will be in a follow-up)

@kyle-cochran kyle-cochran force-pushed the users/kyle/py-custom-state-constructor branch from 079d82a to 9e8185a Compare October 12, 2023 23:20
Copy link
Contributor

@vishwa2710 vishwa2710 left a comment

Choose a reason for hiding this comment

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

LGTM!
It's gonna be sick when we add the custom kwargs and getters 🥳

@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

Merging #244 (98d9016) into main (e93ad85) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #244      +/-   ##
==========================================
+ Coverage   83.23%   83.27%   +0.04%     
==========================================
  Files          63       63              
  Lines        4874     4886      +12     
==========================================
+ Hits         4057     4069      +12     
  Misses        817      817              
Files Coverage Δ
...penSpaceToolkit/Astrodynamics/Trajectory/State.cpp 100.00% <100.00%> (ø)

Co-authored-by: Vishwa Shah <vishwa2710@gmail.com>
Copy link
Contributor

@phc1990 phc1990 left a comment

Choose a reason for hiding this comment

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

I wonder whether we can achieve this by using bindings directly and not Python code 🤔
I just dont' know

@kyle-cochran kyle-cochran merged commit 2200a55 into main Oct 13, 2023
@kyle-cochran kyle-cochran deleted the users/kyle/py-custom-state-constructor branch October 13, 2023 20:23
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