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

Enable observers to create final report #477

Open
stefan-k opened this issue Feb 29, 2024 · 0 comments
Open

Enable observers to create final report #477

stefan-k opened this issue Feb 29, 2024 · 0 comments
Labels
argmin Related to argmin enhancement New feature or request help wanted Extra attention is needed

Comments

@stefan-k
Copy link
Member

It could be useful to allow observers to collect data during the run and then optionally create a final report. There are however a couple of issues.

Observers are stored as dyn Observe (where Observe is a trait) inside a Vec in the Executor (ObserversVec to be precise). ObserversVec is defined as:

type ObserversVec<I> = Vec<(Arc<Mutex<dyn Observe<I>>>, ObserverMode)>;

where I represents the state, which is the same for all observers in a run.

They are not returned from the Executor. Even if they are returned from the Executor at the end of the run, all that is known is the interface, therefore creating the report probably needs to be part of the Observe trait. The report creation could look something like this:

pub trait Observe<I> {
    /// [...]

    fn report<R>(&mut self, _state: &I) -> Result<R, Error> {
        Ok(())
    }
}

Unfortunately that makes Observe not object safe and hence ObserversVec doesn't work anymore. Even if it were possible, it wouldn't work because if Executor returns the list of observers and the user calls report(..) on every observer, the resulting type depends on the observer, which is against how Rust works. I can't think of a "common" R that would work for all possible kinds of reports, therefore this has to be generic. The obvious alternative would be

pub trait Observe<I, R> {
    /// [...]

    fn report(&mut self, _state: &I) -> Result<R, Error> {
        Ok(())
    }
}

but that obviously doesn't work either because that requires all observers in ObserversVec to produce the same report.

A Report trait won't solve any of these issues either.

The only thing I can think of is some kind of ReportStorage, with interior mutability which is shared with the observer, where the observer can push information into. This storage outlives the observer and one can call report(...) on it afterwards. ReportStorage wouldn't be part of argmin as it would be highly dependent on what kind of report it produces. This could already be done with the current interface, but isn't straightforward to document.

Any ideas are highly welcome!

@stefan-k stefan-k added enhancement New feature or request help wanted Extra attention is needed argmin Related to argmin labels Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
argmin Related to argmin enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant