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

Add reference from within function, based on input #8

Open
valentinsulzer opened this issue Feb 13, 2020 · 4 comments
Open

Add reference from within function, based on input #8

valentinsulzer opened this issue Feb 13, 2020 · 4 comments
Assignees

Comments

@valentinsulzer
Copy link
Collaborator

valentinsulzer commented Feb 13, 2020

Functionality to allow references to be added based on inputs would be useful. The use case is for setting parameters within PyBaMM. For example, in the following case, I would like to reference a different citation based on which parameter dictionary is used:

def set_parameters(parameters):
    do_the_parameter_setting
    r2t2.reference("Parameters used for simulation", parameters["citation"])

set_parameters({"a": 1, "b": 2, "citation": "some2018paper"}) # the first dictionary
set_parameters({"a": 4, "b": 3, "citation": "another2017paper"}) # the second dictionary
@rgaiacs
Copy link
Contributor

rgaiacs commented Sep 1, 2020

This adds complexity to the code. I would recommend that users have two wrappers:

from r2t2 import add_reference

@add_reference("old_paper")
def my_great_function(a, b):
    pass

@add_reference("some2018paper")
def my_great_function2018():
    my_great_function(1, 2)

@add_reference("another2017paper")
def my_great_function2017():
    my_great_function(4, 3)

@dalonsoa
Copy link
Collaborator

dalonsoa commented Sep 2, 2020

@rgaiacs I think this is unfeasible when you have many functions acceping different sets of parameters. I would say that the reference in this case should be added when loading/setting the parameters to start with (just once), not in every function that can potentially accept different parameters.

@tinosulzer, was this the use case you were refering to?

@rgaiacs
Copy link
Contributor

rgaiacs commented Sep 2, 2020

@dalonsoa The user case that I was considering was: Alice implements a new new algorithm and the package that Alice publishes has

from r2t2 import add_reference

@add_reference("alice")
def my_great_function(a, b):
    pass

Bob uses Alice's implementation when searching for the "optimal" parameters a and b. Bob publishes the code that search for the "optimal" parameters a and b where Bob uses

from r2t2 import add_reference
import alice

@add_reference("bob")
def my_great_function_optimal_parameters():
    alice.my_great_function(1, 2)

When Eve will use Bob's parameters, Eve can import Bob's package (if it exists) or create a function like Bob did.

@valentinsulzer
Copy link
Collaborator Author

The use case I was thinking is if the citation key is passed as an argument (e.g. a dictionary key), so the citation is for some "information" (e.g. a set of parameters) rather than code

@valentinsulzer valentinsulzer self-assigned this Sep 3, 2020
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

No branches or pull requests

3 participants