Run both hazard and risk, one after the other
350193
def run2(job_haz, job_risk, calc_id, concurrent_tasks, pdb, loglevel,
         exports, params):
    
    hcalc = base.calculators(readinput.get_oqparam(job_haz), calc_id)
    hcalc.run(concurrent_tasks=concurrent_tasks, pdb=pdb,
              exports=exports, **params)
    hc_id = hcalc.datastore.calc_id
    rcalc_id = logs.init(level=getattr(logging, loglevel.upper()))
    oq = readinput.get_oqparam(job_risk, hc_id=hc_id)
    rcalc = base.calculators(oq, rcalc_id)
    rcalc.run(pdb=pdb, exports=exports, **params)
    return rcalc
580659
def constrain_bounded(self, lower, upper, warning=True, trigger_parent=True):
        
        self.constrain(Logistic(lower, upper), warning=warning, trigger_parent=trigger_parent)
433416
def safe_either(method, dictionary, key1, key2, default_value=None):
        """"""
        value = method(dictionary, key1)
        return value if value is not None else method(dictionary, key2, default_value)
506325
def gen_outputs(self, riskinput, monitor, epspath=None, hazard=None):
        
        self.monitor = monitor
        hazard_getter = riskinput.hazard_getter
        if hazard is None:
            with monitor('getting hazard'):
                hazard_getter.init()
                hazard = hazard_getter.get_hazard()
        sids = hazard_getter.sids
        assert len(sids) == 1
        with monitor('computing risk', measuremem=False):
            # this approach is slow for event_based_risk since a lot of
            # small arrays are passed (one per realization) instead of
            # a long array with all realizations; ebrisk does the right
            # thing since it calls get_output directly
            assets_by_taxo = get_assets_by_taxo(riskinput.assets, epspath)
            for rlzi, haz in sorted(hazard[sids[0]].items()):
                out = self.get_output(assets_by_taxo, haz, rlzi)
                yield out
539905
def run(self):
        
        # The "or" part is for Python 2.6
        while not (self.finished.wait(self.interval)
                   or self.finished.is_set()):
            self.function(*self.args, **self.kwargs)
1290920
def run(self, error_on_warning=False, verbose=False):
        
        warnings, criticals = self.check_limits(verbose=verbose)
        # output
        if len(warnings) > 0:
            print("\nWARNING:\n")
            for w in warnings:
                print(w)
        if len(criticals) > 0:
            print("\nCRITICAL:\n")
            for c in criticals:
                print(c)

        # summary
        if len(warnings) > 0 or len(criticals) > 0:
            print("\n{c} limit(s) above CRITICAL threshold; {w} limit(s) above "
                  "WARNING threshold".format(c=len(criticals), w=len(warnings)))
        else:
            print("All limits are within thresholds.")
        if (len(warnings) > 0 and error_on_warning) or len(criticals) > 0:
            raise SystemExit(1)
1301719
def execute(self):
        
        if not hasattr(self, 'riskinputs'):  # in the reportwriter
            return
        res = Starmap.apply(
            self.core_task.__func__,
            (self.riskinputs, self.riskmodel, self.param, self.monitor()),
            concurrent_tasks=self.oqparam.concurrent_tasks or 1,
            weight=get_weight
        ).reduce(self.combine)
        return res
481824
def _priority_from_env(self, val):
        """"""
        for part in val.split(':'):
            try:
                rule, priority = part.split('=')
                yield rule, int(priority)
            except ValueError:
                continue
1028661
function(options) {
  "use strict";
  stream.Transform.call(this, options);

  options = options || {};

  this.probability = options.probability || 0;
  this.deviation = Math.abs(options.deviation || 0);

  this.whiteList = options.whiteList || [];
  this.blackList = options.blackList || [];
  this.func = options.func;
}
1304304
def singlerun(job, task_id=0, job_id=0):
    """"""

    import ecell4_base
    import ecell4
    import ecell4.util.simulation
    import ecell4.util.decorator
    print('ecell4_base.__version__ = {:s}'.format(ecell4_base.__version__))
    print('ecell4.__version__ = {:s}'.format(ecell4.__version__))
    print('job={}, task_id={}, job_id={}'.format(str(job), task_id, job_id))

    with ecell4.util.decorator.reaction_rules():
        A + B == C | (0.01, 0.3)

    res = ecell4.util.simulation.run_simulation(
        1.0,
        y0={'A': job[0], 'B': job[1], 'C': job[2]},
        rndseed=job_id,
        solver='gillespie',
        return_type='array')

    print('A simulation was successfully done.')
    return res
791619
def run(self, *args, **kwargs):
        """"""
        return_value = self.coro(*args, **kwargs)

        # i don't like this but greenlets are so dodgy i have no other choice
        raise StopIteration(return_value)
1356212
def before_scenario(context, scenario):
    """"""

    # Prepare a new temporary directory.
    context.directory = testfixtures.TempDirectory(create=True)
    context.old_cwd = os.getcwd()
    context.new_cwd = context.directory.path

    # Move into our new working directory.
    os.chdir(context.new_cwd)
230788
def blow(self):
        """"""

        if self.verbose > 1:
            print_('\t' + self._id + ' Running ')

        # Mask for values to move
        phi = self.phi

        if self._prime:
            xp, x = self.values
        else:
            x, xp = self.values

        if self.verbose > 1:
            print_('\t' + 'Current value ' + str(x))

        sigma = max(phi * abs(xp - x))

        x = x + phi * sigma * rnormal()

        if self.verbose > 1:
            print_('\t' + 'Proposed value = ' + str(x))

        self.hastings_factor = self._g(
            x,
            xp,
            sigma) - self._g(
                self.stochastic.value,
                xp,
                sigma)

        self.stochastic.value = x
836024
function def (params, spec, errs) {
  for (var key in params) {
    if (!spec.hasOwnProperty(key)) defError(key, errs)
  }
}
358806
def accept(self):
        """"""
        mode = None
        if self.hazard_exposure_view_extent.isChecked():
            mode = HAZARD_EXPOSURE_VIEW
        elif self.exposure_only.isChecked():
            mode = EXPOSURE
        elif self.hazard_exposure_only.isChecked():
            mode = HAZARD_EXPOSURE
        elif self.hazard_exposure_bookmark.isChecked():
            mode = HAZARD_EXPOSURE_BOOKMARK
        elif self.hazard_exposure_user_extent.isChecked():
            mode = HAZARD_EXPOSURE_BOUNDINGBOX

        set_setting('analysis_extents_mode', mode)

        self.canvas.unsetMapTool(self.tool)
        if self.previous_map_tool != self.tool:
            self.canvas.setMapTool(self.previous_map_tool)

        if not self.tool.rectangle().isEmpty():
            self.extent_defined.emit(
                self.tool.rectangle(),
                self.canvas.mapSettings().destinationCrs())
            extent = QgsGeometry.fromRect(self.tool.rectangle())
            LOGGER.info(
                'Requested extent : {wkt}'.format(wkt=extent.asWkt()))
        else:
            self.clear_extent.emit()

        # State handlers for showing warning message bars
        set_setting('show_extent_warnings', self.show_warnings.isChecked())
        set_setting(
            'show_extent_confirmations', self.show_confirmations.isChecked())

        self.tool.reset()
        self.extent_selector_closed.emit()
        super(ExtentSelectorDialog, self).accept()
367558
def _runAuction(self, gteeOfferPrice, gteeBidPrice, haveQ):
        
        pOffers = [offer for offer in self.offers if not offer.reactive]
        pBids = [bid for bid in self.bids if not bid.reactive]

        # Clear offer/bid quantities and prices.
        auction = Auction(self.case, pOffers, pBids, self.auctionType,
                          gteeOfferPrice, gteeBidPrice, self.limits)
        auction.run()

        # Separate auction for reactive power.
        if haveQ:
            qOffers = [offer for offer in self.offers if offer.reactive]
            qBids = [bid for bid in self.bids if bid.reactive]

            # Too complicated to scale with mixed bids/offers (only
            # auction_types LAO and FIRST_PRICE allowed)
            qAuction = Auction(self.case, qOffers, qBids, self.auctionType,
                                gteeOfferPrice, gteeBidPrice, self.limits)
            qAuction.run()
422514
def extend_safe(target, source):
    
    for elt in source:
        if elt not in target:
            target.append(elt)