[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [HTCondor-users] Python bindings: ExprTree vs classad.eval




> On Feb 5, 2021, at 9:02 AM, Thomas Hartmann <thomas.hartmann@xxxxxxx> wrote:
> 
> Hi all,
> 
> two Python binding questions here:
> 
> 1)
> 
> I tried to use the classad.ExprTree on an ad, but only got the un-evaluated string - I implicitly assumed, that it would be evaluated as calling the ad's eval()
> 
> E.g., I have got an ad coming from the CondorCE to the Condor Sched
>  RequestCpus = "ifThenElse(WantWholeNode is true, !isUndefined(TotalCpus) ? TotalCpus : JobCpus,OriginalCpus)"
> 
> that I tried to evaluate like
>  >>> pprint.pprint( classad.ExprTree( myjob["RequestCpus"] )  )
> 
> but which gave me the expression string
>  >>> "ifThenElse..."
> 
> So, asking the ad directly
>  >>> pprint.pprint(ajob.eval("RequestCpus") )
>  >>> 8L
> worked fine
> 
> I had assumed, that calling the ExprTree() function on an ad would be the same as the eval() function of the ad itself - but apparently not?
> 

classad.ExprTree() is a constructor for the ExprTree object - it results in an expression object.

.eval() is a method on the ClassAd object that evaluates the expression returns a "plain python object" (to the best of its ability).

You'll likely will use classad.ExprTree in very few places (it's useful for manipulating expressions or handling things that cannot be represented in python - rare use cases for scripting condor); I suspect you are really wanting to use eval().

> ------
> 
> 2)
> 
> and somewhat related(?):
> 
> I had assumed, that I would have to query all a job's class ads, that are part of a more complex ad
>  schedd.query('',["TotalCpus", "OriginalCpus", "RequestCpus",'WantWholeNode','JobCpus, ...etc.... ] )
> 
> but then I noted, that it seems not to be necessary to query all involved ads explicitly (actually, I noticed, that I forgot one ad).
> 
> Question: When querying a compound ad - are all involved ads automatically queried?
> which would be really neat, as I would not attempt anymore to count all involved ads in advance ;)
> 

I'm not exactly following.  Each job is represented by a single ClassAd.  Do you mean the job attributes?

When you list the attributes you want, HTCondor will sometimes return additional attributes (e.g., they may be necessary to evaluate or there's a list of attributes you always need).  If you specify nothing at all, the default is "return all attributes"; be careful there as it may cause more load than you intended.

Brian