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

Deserialization for Kernel #221

Closed
Mec-iS opened this issue Nov 3, 2022 · 2 comments · Fixed by #232
Closed

Deserialization for Kernel #221

Mec-iS opened this issue Nov 3, 2022 · 2 comments · Fixed by #232
Assignees
Milestone

Comments

@Mec-iS
Copy link
Collaborator

Mec-iS commented Nov 3, 2022

Kernel is now an object-safe trait so we can use its type as &dyn Kernel, it has also a name() function to have a string representation of the kernel as LinearKernel, RBFKernel, ...

We would like to provide a functionality that instantiate the kernel's default from a string:

"LinearKernel" -> LinearKernel::Default()

via a enum

pub enum KernelName {
    Linear(LinearKernel),
   ...
}

This possibility is known to be not possible in vanilla Rust but there is a library that provides it, see blogpost.

This feature should be only available and loaded in pairing with the "serde" feature so to avoid adding another library to the deps.

This will allow parameters that contain pub kernel: Option<&'a dyn Kernel<'a>>, to be deserializable.

@Mec-iS Mec-iS added this to the v0.5 milestone Nov 3, 2022
@Mec-iS Mec-iS changed the title Serailization and deserialization for Kernel Deserialization for Kernel Nov 3, 2022
@morenol
Copy link
Collaborator

morenol commented Nov 4, 2022

I can take this, I think that we can get ride of name in Kernel trait, and instead handle that in the enum using:
#[serde(tag = "kernel_variant")]

@Mec-iS
Copy link
Collaborator Author

Mec-iS commented Nov 4, 2022

ok, the problem with Rust comes when is needed to go string->instance. there is no easy way like in Python getattr(module, string) to point to a class/type from a string/enum key.

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 a pull request may close this issue.

2 participants