Slackbot
05/03/2023, 12:51 PMElijah Ben Izzy
05/03/2023, 3:45 PMElijah Ben Izzy
05/03/2023, 3:45 PMElijah Ben Izzy
05/03/2023, 3:46 PMAurélien Kinet
05/04/2023, 12:08 PMElijah Ben Izzy
05/04/2023, 1:55 PMElijah Ben Izzy
05/05/2023, 4:05 AM(feature_name, git_hash)
, but you’ll have to compute a ton if you change anything. You could probably optimize for file hash if you wanted to (git allows you to do that, as do other VCSs)
b. version based off of a hash of the code version — this uses something on the main branch (a convenience function), that we’re planning on releasing imminently. Here’s some code:
In this case I’ve created a driver with one “feature” just to demo:
>> dr.list_available_variables()
[Variable(name='foo', type=<class 'int'>, tags={'module': 'temporary_module_8813b8ba_e321_4b96_9a09_8152c45220e3'}, is_external_input=False, originating_functions=(<function foo at 0x10360e040>,)),
Variable(name='b', type=<class 'int'>, tags={}, is_external_input=True, originating_functions=None)]
Note that you can grab the “originating functions” of the node by doing this. If it is None
that means its an external input:
>> feature = dr.list_available_variables()[0]
>> print(feature.originating_functions)
(<function temporary_module_8813b8ba_e321_4b96_9a09_8152c45220e3.foo(b: int) -> int>,)
Then you can grab the code:
>> code = inspect.getsource(feature.originating_functions[0])
>> print(code)
@config.when(a=None)
def foo(b: int) -> int:
return b
Which includes the code + all decorators. Finally you can add a hash:
>> hashlib.sha256(code.encode('utf-8')).hexdigest()
Out[35]: '06ec36295a2978b5e6298f23f5d9df8f01fff75511e11bfc931a032b81b66713'
And then you have a unique version! When the code changes, the function will as well.
Finally, you have:
c: Handle versions yourself
@config.when(foo_version=1)
def foo__v1() -> ...:
...
@config.when(foo_version=2)
def foo__v2() -> ...:
...
@config.when(foo_version=None) # default
def foo() -> ...:
...
Its verbose, but it allows you to keep around old versionsElijah Ben Izzy
05/05/2023, 4:06 AMElijah Ben Izzy
05/05/2023, 4:08 AM>> vars = dr.list_available_variables()
>> var = vars[...]
>> var.version_hash()
'06ec36295a2978b5e6298f23f5d9df8f01fff75511e11bfc931a032b81b66713'
And now you can see the reason we haven’t added it yet, everyone wants something different so we’ve given you the lower-level tools to make it pretty easy on top 🙂 Happy to chat more about it or hop on a call some time tomorrow if you want to talk through the options.