Giter VIP home page Giter VIP logo

xdeps's Introduction

Xdeps

Value dependency manager with convenient syntax for expressions dependency.

Example

s={'a': 1, 'b': 2} # Assume a container exists

import xdeps
m=xdeps.Manager() # Create dependency manager
s_=m.ref(s,'s') # Create a reference to the container

s_['c']= s_['a']+s_['b'] # Now s['c'] depends on s_['a'] and s_['b']
s_._exec('d=c+b') # Same as above using a convenient function to save typing
s_['a']=1.1 # This updates 'a' and anything depending on 'a' such as 'c' and 'd'
assert s['c']==s['a']+s['b']
assert s['d']==s['c']+s['b']

s_['a']+=1.1 # Increment a
assert s['c']==s['a']+s['b']
assert s['d']==s['c']+s['b']

s_['c']+=s_['b']*2 # Modify expression
print(s_['c']._expr) # Inspect c-> ((s['a']+s['b'])+(s['b']*2))

set_ab=m.gen_fun('set_ab',a=s_['a'],b=s_['b']) # generate setter function
set_ab(2.3,1.2) # set a, b and dependecies
assert s['c']==s['a']+s['b']+s['b']*2
assert s['d']==s['c']+s['b']

dump=m.dump() # save the dependencies
m2=xdeps.Manager() # create a new manager
s2_=m.ref(s,'s') # set a reference to the container
m2.load(dump) # load dependencies

m2.plot_deps(backend='os') # Inspect depency graph

Example

Description

The library is based on a manager mgr=xdeps.Manager() that manages tasks and dependencies.

A Task is an instance that has:

  • A taskid
  • A set of targets
  • A set of dependecies
  • A method run() that uses the dependecies to update the targets.

A Task can be registered using mgr.register(task) or removed using mgr.unregister(task).

Target and dependencies can be defined by a Ref object that can be obtained by s_=mgr.ref(s,'s') where s can be a dictionary or an instance. The label 's' is necessary for printing, but also to save and restore dependencies and must be unique. mgr.set_value(ref,value) set the value into the reference ref and call the tasks that depends on ref.

A reference of a part of s could be obtained using standard Python syntax such as s_.a or s_['b'][0].a etc...

A Ref object could be used to define expressions such as ex=s_.a*2+3 that can be evaluated using ex._get_value().

A Ref of a cointainer can be assigned to an expression. This creates a special ExprTask that is registered in the manager. If an expressions was already created, it is replaced.

A Ref of a cointainer can be assigned to a value. In this case the value is assigned to the container that the tasks that depends on the reference are called in the correct ordering. Also in this case if an expressions was already created, it is deleted.

xdeps's People

Contributors

giadarol avatar rdemaria avatar szymonlopaciuk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.