Changeset 2401


Ignore:
Timestamp:
Feb 24, 2010 5:08:49 PM (9 years ago)
Author:
jwatson
Message:

PH solver manager and servers now handle rho and weight/average update requests correctly.

Location:
coopr.pysp/trunk/coopr/pysp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • coopr.pysp/trunk/coopr/pysp/ph.py

    r2398 r2401  
    454454
    455455   # a utility to transmit - across the PH solver manager - the current weights
    456    # for each of my problem instances. used to set up iteration K solves.
    457    def _transmit_weights(self):
     456   # and averages for each of my problem instances. used to set up iteration K solves.
     457   def _transmit_weights_and_averages(self):
    458458
    459459      for scenario_name, scenario_instance in self._instances.items():
    460460
    461461         weights_to_transmit = []
     462         averages_to_transmit = []
    462463
    463464         for stage in self._scenario_tree._stages[:-1]: # no blending over the final stage, so no weights to worry about.
     
    468469               weight_parameter_name = "PHWEIGHT_"+variable_name
    469470               weights_to_transmit.append(getattr(scenario_instance, weight_parameter_name))
    470 
    471          self._solver_manager.transmit_weights(scenario_instance, weights_to_transmit)
     471               average_parameter_name = "PHAVG_"+variable_name
     472               averages_to_transmit.append(getattr(scenario_instance, average_parameter_name))               
     473
     474         self._solver_manager.transmit_weights_and_averages(scenario_instance, weights_to_transmit, averages_to_transmit)
    472475
    473476   # a utility to transmit - across the PH solver manager - the current rho values
     
    12911294      #       transmitted if needed.
    12921295      if self._solver_manager_type == "ph":
    1293          self._transmit_weights()
     1296         self._transmit_weights_and_averages()
    12941297
    12951298      # STEP 0: set up all global solver options.
  • coopr.pysp/trunk/coopr/pysp/phserver.py

    r2398 r2401  
    6666      return encoded_results
    6767
    68    def update_weights(self, scenario_name, new_weights):
    69 
    70       print "RECEIVED REQUEST TO UPDATE WEIGHTS FOR SCENARIO=",scenario_name
    71       print "WEIGHT LIST=",new_weights
    72       for update_weight in new_weights:
    73          update_weight.pprint()
    74       # TBD - FIND THE RIGHT SCENARIO INSTANCE, APPLY THE UPDATES, ETC!
     68   def update_weights_and_averages(self, scenario_name, new_weights, new_averages):
     69
     70      print "RECEIVED REQUEST TO UPDATE WEIGHTS AND AVERAGES FOR SCENARIO=",scenario_name
     71
     72      if scenario_name not in self._scenario_instances:
     73         print "***ERROR: Received request to update weights for instance not in PH solver server instance collection!"
     74         return None
     75      scenario_instance = self._scenario_instances[scenario_name]
     76     
     77      for weight_update in new_weights:
     78         weight_update.pprint()
     79         
     80         weight_index = weight_update._index
     81
     82         target_weight_parameter = getattr(scenario_instance, weight_update.name)
     83
     84         for index in weight_index:
     85            target_weight_parameter[index] = weight_update[index]
     86
     87      for average_update in new_averages:
     88         average_update.pprint()
     89         
     90         average_index = average_update._index
     91
     92         target_average_parameter = getattr(scenario_instance, average_update.name)
     93
     94         for index in average_index:
     95            target_average_parameter[index] = average_update[index]           
    7596
    7697   def update_rhos(self, scenario_name, new_rhos):
    7798
    7899      print "RECEIVED REQUEST TO UPDATE RHOS FOR SCENARIO=",scenario_name
    79       print "RHO LIST=",new_rhos
    80       for update_rho in new_rho:
    81          update_rho.pprint()
    82       # TBD - FIND THE RIGHT SCENARIO INSTANCE, APPLY THE UPDATES, ETC!     
    83 
     100
     101      if scenario_name not in self._scenario_instances:
     102         print "***ERROR: Received request to update weights for instance not in PH solver server instance collection!"
     103         return None
     104      scenario_instance = self._scenario_instances[scenario_name]     
     105
     106      for rho_update in new_rhos:
     107         rho_update.pprint()
     108         
     109         rho_index = rho_update._index
     110
     111         target_rho_parameter = getattr(scenario_instance, rho_update.name)
     112
     113         for index in rho_index:
     114            target_rho_parameter[index] = rho_update[index]
     115           
    84116#
    85117# utility method to construct an option parser for ph arguments, to be
     
    255287   start_time = time.time()
    256288
    257    Pyro.core.initServer(banner=1)   
     289   Pyro.core.initServer(banner=0)   
    258290
    259291   locator = Pyro.naming.NameServerLocator()
  • coopr.pysp/trunk/coopr/pysp/phsolvermanager.py

    r2398 r2401  
    115115        return ActionHandle(error=True, explanation="No queued evaluations available in the PH solver manager, which only executes solvers synchronously")
    116116
    117     def transmit_weights(self, scenario_instance, new_weights):
     117    def transmit_weights_and_averages(self, scenario_instance, new_weights, new_averages):
    118118
    119        if isinstance(scenario_instance, Model) is False:
    120           raise RuntimeError, "Argument supplied to _perform_queue method of class PHSolverManager must be a Model instance - type supplied="+str(type(scenario_instance))
    121119       scenario_name = scenario_instance.name
    122120
     
    137135
    138136       # execute the RMI.
    139        proxy.update_weights(scenario_name, new_weights)
     137       proxy.update_weights_and_averages(scenario_name, new_weights, new_averages)
     138
     139    def transmit_rhos(self, scenario_instance, new_rhos):
     140
     141       scenario_name = scenario_instance.name
     142
     143       # identify the appropriate PH solver server, grabbing a handle if necessary.
     144       # TBD: The code block for extracting the proxy should be made common within the module.
     145       proxy = None
     146       if scenario_name in self._solver_proxy.keys():
     147          proxy = self._solver_proxy[scenario_name]
     148       else:
     149          uri = None
     150          try:
     151             uri = self._ns.resolve(scenario_name)
     152          except Pyro.errors.NamingError:
     153             raise RuntimeError, "***ERROR: Failed to locate PH solver server capable of processing scenario="+scenario_name
     154             sys.exit(0)
     155             
     156          proxy = Pyro.core.getProxyForURI(uri)
     157          self._solver_proxy[scenario_name] = proxy
     158
     159       # execute the RMI.
     160       proxy.update_rhos(scenario_name, new_rhos)
    140161
    141162SolverManagerRegistration("ph", PHSolverManager)
Note: See TracChangeset for help on using the changeset viewer.