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

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



Hi Brian,

On 05/02/2021 16.56, Bockelman, Brian wrote:
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().

ah, good to know

I found ExprTree() in the documentation and wanted to try it out ;)


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.

thing is, that I can query for a limited set of ads and it seems, that I can still successfully evaluate an ad from the list - where the ad is a compound of ads, that have not been necessarily queried explicitly and thus are not in the query result

e.g.,

>>> myjob = schedd.query('',["TotalCpus","GlobalJobId","Owner","RequestCpus"])

  >>> print(myjob.get("RequestCpus") )
>>> ifThenElse(WantWholeNode is true, !isUndefined(TotalCpus) ? TotalCpus : JobCpus,OriginalCpus)

  >>> myjob.eval("RequestCpus")
  >>> 8L

>>> if "OriginalCpus" in list(myjob.keys() ): print("OriginalCpus is in the ads..."
  >>> OriginalCpus is in the ads...

  >>> print(myjob.get("OriginalCpus") )
  8

where I have not been querying for 'OriginalCpus' explicitly - but it appears in the result ad list nevertheless
(which is good, else I would have forgotten it ;) )

Cheers,
  Thomas

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature