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

Nexus: Quantum Package interface #1093

Merged
merged 15 commits into from
Oct 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
641 changes: 640 additions & 1 deletion nexus/executables/ntest

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion nexus/library/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ def __init__(self,*sims,**kwargs):
#end if
sims = list(sims) # make a copy
if len(sims)==0:
self.error('attempted to bundle 0 simulations\n at least one simulation must be provided to bundle')
self.error('attempted to bundle 0 simulations\nat least one simulation must be provided to bundle')
#end if
for sim in sims:
if not isinstance(sim,Simulation):
self.error('attempted to bundle non-simulation object: '+sim.__class__.__name__)
elif not sim.bundleable:
self.error('attempted to bundle simulation that does not support bundling\nsim type: {0}\nsim identifier: {1}\nsim directory: {2}'.format(sim.__class__.__name__,sim.identifier,sim.locdir))
#end if
sim.bundled = True
sim.bundler = self
Expand Down
120 changes: 105 additions & 15 deletions nexus/library/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def add_optional(self,key,value):
#end def add_optional

def transfer_from(self,other,keys=None,copy=False,overwrite=True):
if keys==None:
if keys is None:
if isinstance(other,object_interface):
keys = other._keys()
else:
Expand All @@ -776,7 +776,7 @@ def transfer_from(self,other,keys=None,copy=False,overwrite=True):
#end def transfer_from

def transfer_to(self,other,keys=None,copy=False,overwrite=True):
if keys==None:
if keys is None:
keys = self._keys()
#end if
if copy:
Expand All @@ -797,30 +797,56 @@ def transfer_to(self,other,keys=None,copy=False,overwrite=True):
#end if
#end def transfer_to

def move_from(self,other,keys=None):
if keys==None:
def move_from(self,other,keys=None,optional=False):
if keys is None:
if isinstance(other,object_interface):
keys = other._keys()
else:
keys = other.keys()
#end if
#end if
for k in keys:
self[k]=other[k]
del other[k]
#end for
if not optional:
for k in keys:
self[k]=other[k]
del other[k]
#end for
else:
for k in keys:
if k in other:
self[k]=other[k]
del other[k]
#end if
#end for
#end if
#end def move_from

def move_to(self,other,keys=None):
if keys==None:
def move_to(self,other,keys=None,optional=False):
if keys is None:
keys = self._keys()
#end if
for k in keys:
other[k]=self[k]
del self[k]
#end for
if not optional:
for k in keys:
other[k]=self[k]
del self[k]
#end for
else:
for k in keys:
if k in self:
other[k]=self[k]
del self[k]
#end if
#end for
#end if
#end def move_to

def move_from_optional(self,other,keys=None):
self.move_from(other,keys,optional=True)
#end def move_from_optional

def move_to_optional(self,other,keys=None):
self.move_to(other,keys,optional=True)
#end def move_to_optional

def copy_from(self,other,keys=None,deep=True):
obj.transfer_from(self,other,keys,copy=deep)
#end def copy_from
Expand All @@ -829,6 +855,57 @@ def copy_to(self,other,keys=None,deep=True):
obj.transfer_to(self,other,keys,copy=deep)
#end def copy_to

def extract(self,keys=None,optional=False):
ext = obj()
ext.move_from(self,keys,optional=optional)
return ext
#end def extract

def extract_optional(self,keys=None):
return self.extract(keys,optional=True)
#end def extract_optional

def check_required(self,keys,exit=True):
if not isinstance(keys,set):
keys = set(keys)
#end if
missing = keys-set(self.keys())
if exit and len(missing)>0:
self._error('required keys are missing\nmissing keys: {0}'.format(sorted(missing)))
#end if
return missing
#end def check_required

def check_types(self,types,optional=False,exit=True):
kfail = None
tfail = None
if not optional:
for k,t in types.iteritems():
if not isinstance(self[k],t):
kfail = k
tfail = t
break
#end if
#end for
else:
for k,t in types.iteritems():
if k in self and not isinstance(self[k],t):
kfail = k
tfail = t
break
#end if
#end for
#end if
if exit and kfail is not None:
self._error('incorrect type encountered for key value\ntype required: {0}\ntype encountered: {1}\ninvalid key: {2}'.format(tfail.__name__,self[kfail].__class__.__name__,kfail))
#end if
return kfail,tfail
#end def check_types

def check_types_optional(self,types,exit=True):
return self.check_types(types,exit=exit,optional=True)
#end def check_types_optional

def shallow_copy(self):
new = self.__class__()
for k,v in self._iteritems():
Expand Down Expand Up @@ -917,7 +994,6 @@ def serial(self,s=None,path=None):
#end def serial



# access preserving functions
# list interface
def _append(self,*args,**kwargs):
Expand Down Expand Up @@ -973,10 +1049,24 @@ def _move_from(self,*args,**kwargs):
obj.move_from(self,*args,**kwargs)
def _move_to(self,*args,**kwargs):
obj.move_to(self,*args,**kwargs)
def _move_from_optional(self,*args,**kwargs):
obj.move_from_optional(self,*args,**kwargs)
def _move_to_optional(self,*args,**kwargs):
obj.move_to_optional(self,*args,**kwargs)
def _copy_from(self,*args,**kwargs):
obj.copy_from(self,*args,**kwargs)
def _copy_to(self,*args,**kwargs):
obj.copy_to(self,*args,**kwargs)
def _extract(self,*args,**kwargs):
obj.extract(self,*args,**kwargs)
def _extract_optional(self,*args,**kwargs):
obj.extract_optional(self,*args,**kwargs)
def _check_required(self,*args,**kwargs):
obj.check_required(self,*args,**kwargs)
def _check_types(self,*args,**kwargs):
obj.check_types(self,*args,**kwargs)
def _check_types_optional(self,*args,**kwargs):
obj.check_types_optional(self,*args,**kwargs)
def _shallow_copy(self,*args,**kwargs):
obj.shallow_copy(self,*args,**kwargs)
def _inverse(self,*args,**kwargs):
Expand Down
Loading