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

simHcalTriggerPrimitiveDigis.weightsQIE11 PSet uses number as keyword #32047

Closed
silviodonato opened this issue Nov 6, 2020 · 9 comments
Closed

Comments

@silviodonato
Copy link
Contributor

Minimal code to reproduce the error. Create a file test.py containing

import FWCore.ParameterSet.Config as cms
process = cms.Process("TEST")
process.load('SimCalorimetry.HcalTrigPrimProducers.hcaltpdigi_cfi')
process.p = cms.Path(process.simHcalTriggerPrimitiveDigis)                                                                    

Then

edmConfigDump test.py > dump.py && python dump.py

gives

  File "dump.py", line 105
    1 = cms.untracked.vdouble(1.0, 1.0),
SyntaxError: keyword can't be an expression

The origin of the problem is #31661 which defines weightsQIE11 using dict

    weightsQIE11 = cms.untracked.PSet(**dict([
        ("1",  cms.untracked.vdouble(1.0, 1.0)),
        ("2",  cms.untracked.vdouble(1.0, 1.0)),
      [...]

https://github.com/cms-sw/cmssw/blob/master/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py#L19
@JHiltbrand : please rename the variables from "1", "2", ... to something else!
Eg.

    weightsQIE11 = cms.untracked.PSet(
        var1 =  cms.untracked.vdouble(1.0, 1.0),
        var2 =  cms.untracked.vdouble(1.0, 1.0),
      [...]

@cms-sw/core-l2 : please note that python test.py gives no error, while python dump.py gives error. Do you expect this behaviour?

@cmsbuild
Copy link
Contributor

cmsbuild commented Nov 6, 2020

A new Issue was created by @silviodonato Silvio Donato.

@Dr15Jones, @dpiparo, @silviodonato, @smuzaffar, @makortel, @qliphy can you please review it and eventually sign/assign? Thanks.

cms-bot commands are listed here

@silviodonato
Copy link
Contributor Author

assign core, l1

@cmsbuild
Copy link
Contributor

cmsbuild commented Nov 6, 2020

New categories assigned: core,l1

@Dr15Jones,@smuzaffar,@rekovic,@makortel,@jmduarte you have been requested to review this Pull request/Issue and eventually sign? Thanks

@makortel
Copy link
Contributor

makortel commented Nov 6, 2020

please note that python test.py gives no error, while python dump.py gives error. Do you expect this behaviour?

The behavior is not unexpected, the keys of PSet are intended to be valid python identifiers, although when effectively using setattr() "anything" works (until edmConfigDump).

We could think of (somehow) enforcing the keys of PSet to be valid identifiers.

@davidlange6
Copy link
Contributor

davidlange6 commented Nov 6, 2020 via email

@makortel
Copy link
Contributor

makortel commented Nov 6, 2020

I’m naively surprised that python allows this - but ok it does..

Internally they're all dictionaries, and dictionary allows "anything" as keys (e.g. {1: 2}).

Import keyword
if varname.isidentifier() and not keyword.iskeyword(varname)

Thanks, this could be something to look into.

@davidlange6
Copy link
Contributor

davidlange6 commented Nov 6, 2020 via email

@JHiltbrand
Copy link
Contributor

https://github.com/cms-sw/cmssw/blob/master/SimCalorimetry/HcalTrigPrimProducers/python/hcaltpdigi_cfi.py#L19
@JHiltbrand : please rename the variables from "1", "2", ... to something else!
Eg.

    weightsQIE11 = cms.untracked.PSet(
        var1 =  cms.untracked.vdouble(1.0, 1.0),
        var2 =  cms.untracked.vdouble(1.0, 1.0),
      [...]

Hi @silviodonato ,

I am working on the changes now.

@JHiltbrand
Copy link
Contributor

Hi @silviodonato ,

Please refer to #32067 for addressing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants