Skip to content

Add observer layering API via LayeredObserver and FitnessObserver::layer#135

Merged
HyperCodec merged 3 commits intodevfrom
copilot/add-layered-observer-implementation
Mar 2, 2026
Merged

Add observer layering API via LayeredObserver and FitnessObserver::layer#135
HyperCodec merged 3 commits intodevfrom
copilot/add-layered-observer-implementation

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

  • Add LayeredObserver<G, A, B> struct implementing FitnessObserver<G>
  • Add layer default method to FitnessObserver<G> trait
  • Use where syntax on FitnessObserver impl for LayeredObserver
  • Move layered observer tests from derive_macros.rs to a new eliminator.rs test file
  • All tests pass
Original prompt

This section details on the original issue you should resolve

<issue_title>Observer layering API</issue_title>
<issue_description>Currently there's no real way to have multiple FitnessObservers on one FitnessEliminator. I think an easy way to fix this would be like this:

pub struct LayeredObserver<G, A: FitnessOverserver<G>, B: FitnessObserver<G>>(pub A, pub B);

impl<G, A, B> FitnessObserver<G> for LayeredObserver<G, A, B> {
    fn observe(&self, genomes: &[(G, f32)]) {
        self.0.observe(genomes);
        self.1.observe(genomes);
    }
}

And then add a default function in FitnessObserver:

fn layer<O: FitnessObserver<G>>(self, other: O) -> LayeredObserver<G, Self, O> {
    LayeredObserver(self, other)
}

This allows observers to be layered pretty conveniently:

FitnessEliminator::builder()
    .fitness(my_fitness)
    .observer(Foo::default().layer(Bar::default()))
    .build();
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@HyperCodec</author><body>
Probably just going to let AI do this because I don't feel like setting up another codespace for something trivial like this.</body></comment_new>
<comment_new><author>@HyperCodec</author><body>
There is a bit of an efficiency concern with recursively nesting these, but it really shouldn't be an issue unless you have a ridiculous amount of observers, which I don't think anyone actually would do.</body></comment_new>
</comments>

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Copilot AI changed the title [WIP] Add observer layering functionality for FitnessObservers Add observer layering API via LayeredObserver and FitnessObserver::layer Mar 2, 2026
@HyperCodec HyperCodec marked this pull request as ready for review March 2, 2026 13:03
Copy link
Owner

Choose a reason for hiding this comment

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

this is in the derive macros test file. it really shouldn't go there. make an eliminator test file or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to a new genetic-rs/tests/eliminator.rs file in commit 0f76217.

Copy link
Owner

Choose a reason for hiding this comment

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

mostly fine, but probably use the where syntax on the FitnessObserver impl for LayeredObserver.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to where syntax in commit 0f76217.

…rver impl

Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Copy link
Owner

@HyperCodec HyperCodec left a comment

Choose a reason for hiding this comment

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

LGTM

@HyperCodec HyperCodec merged commit bbcc730 into dev Mar 2, 2026
3 checks passed
@HyperCodec HyperCodec deleted the copilot/add-layered-observer-implementation branch March 2, 2026 13:16
@HyperCodec HyperCodec mentioned this pull request Mar 2, 2026
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.

2 participants