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

Add corrections eff #114

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
52 changes: 47 additions & 5 deletions cax/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ def massive():
help="Select the cluster partition")
parser.add_argument('--reservation', type=str,
help="Select the reservation")
parser.add_argument('--no-batch-mode', dest='no_batch_mode', action='store_true',
help="Use massive-cax without batch queue submission.")


args = parser.parse_args()

Expand All @@ -195,6 +198,7 @@ def massive():
exit()

run_once = args.once
no_batch_mode = args.no_batch_mode

config_arg = ''
if args.config_file:
Expand Down Expand Up @@ -288,10 +292,48 @@ def massive():
docs = list(collection.find(query,
sort=sort_key,
projection=['start', 'number','name',
'detector', '_id']))
'detector', '_id', 'processor']))

for doc in docs:

#If no_batch_mode is chosen, no jobs will submitted to batch queues
if no_batch_mode == True:

#Define basic command:
basic_command = """#!/bin/bash
cax --once {config} --name {name}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation problem maybe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be ok for a string definition, similar to this

"""

print("no-batch-mode")

#Pre-read the config file for the no-batch-mode modus:
config.set_json(os.path.abspath(args.config_file))
task_list = config.get_config(config.get_hostname())['task_list']

#This is a list of tasks which refer to apply corrections to a run:
task_list_correction = ['AddElectronLifetime', 'AddGains', 'AddDriftVelocity', 'SetS2xyMap', 'SetLightCollectionEfficiency', 'SetFieldDistortion', 'SetNeuralNetwork']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like put a warning here. If the user doesn't select json file


#--------------------
#Start with single activities: Apply corrections only to data sets which do not have any correction yet:
if bool(set(task_list) & set(task_list_correction)) or task_list_correction == task_list:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so familiar with this bitwise operation on Python sets, but isn't the second condition after the or included in the first condition (i.e. don't need the or)?

Also, what if I want to run in no-batch mode without running corrections?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know exactly what does set, maybe it creates a "set" of elements, but yes, the second command should not to be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is included and you would not mind if you run the full set of corrections such as they are defined in line (

cax/cax/main.py

Line 314 in 144fd4e

task_list_correction = ['AddElectronLifetime', 'AddGains', 'AddDriftVelocity', 'SetS2xyMap', 'SetLightCollectionEfficiency', 'SetFieldDistortion', 'SetNeuralNetwork']
). But in case you run only a subset of corrections it will need to math the condition before the "or".

In case we come up with more corrections we would need to adjust line 314. But I think this is ok.


this_run_version = doc.get('processor', {}).get('correction_versions', {})
if len(this_run_version) == 0:
command = basic_command.format(config=config_arg, name=doc['name'])
logging.info(command)
stdout_value = qsub.command_submission( command )

#Return command output:
for i in stdout_value:
logging.info('AddCorrections: %s', i)

#--------------------
#Start with single activities: Add another activity:

#Nothing else
continue

#Start with processing via batch (if no 'add corrections' was requested)
job_name = ''

if doc['detector'] == 'tpc':
Expand Down Expand Up @@ -336,10 +378,10 @@ def massive():

if run_once:
break
#else:
# pace = 5
# logging.info("Done, waiting %d minutes" % pace)
# time.sleep(60*pace) # Pace 5 minutes
else:
pace = 5
logging.info("Done, waiting %d minutes" % pace)
time.sleep(60*pace) # Pace 5 minutes


def move():
Expand Down
18 changes: 18 additions & 0 deletions cax/qsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,21 @@ def get_queue(host=config.get_hostname(), partition=''):
if len(queue_list) > 1:
return queue_list[1:]
return []


def command_submission(command):

#Submit the command
sc = create_script(command)
execute = subprocess.Popen( ['sh', sc.name] , \
stdin=subprocess.PIPE,\
stdout=subprocess.PIPE,\
stderr=subprocess.STDOUT, shell=False )
stdout_value, stderr_value = execute.communicate()
stdout_value = stdout_value.decode("utf-8")
stdout_value = stdout_value.split("\n")
#delete script:
delete_script( sc )

return stdout_value

2 changes: 0 additions & 2 deletions cax/tasks/corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ def each_run(self):
# We can't do this in init: cax is a long-running application, and corrections may change while it is running.
self.correction_doc = cdoc = self.correction_collection.find_one(sort=(('calculation_time', -1), ))
self.version = cdoc.get('version', str(cdoc['calculation_time']))

# Get the correction sympy function, if one is set
if 'function' in cdoc:
self.function = parse_expr(cdoc['function'])

# Check if this correction's version correction has already been applied. If so, skip this run.
classname = self.__class__.__name__
this_run_version = self.run_doc.get('processor', {}).get('correction_versions', {}).get(classname, 'not_set')
Expand Down