(self, config, ctrl, attach_attachments=True)
| 876 | return memo |
| 877 | |
| 878 | def evaluate(self, config, ctrl, attach_attachments=True): |
| 879 | memo = self.memo_from_config(config) |
| 880 | use_obj_for_literal_in_memo(self.expr, ctrl, Ctrl, memo) |
| 881 | if self.pass_expr_memo_ctrl: |
| 882 | rval = self.fn(expr=self.expr, memo=memo, ctrl=ctrl) |
| 883 | else: |
| 884 | # -- the "work" of evaluating `config` can be written |
| 885 | # either into the pyll part (self.expr) |
| 886 | # or the normal Python part (self.fn) |
| 887 | pyll_rval = pyll.rec_eval( |
| 888 | self.expr, |
| 889 | memo=memo, |
| 890 | print_node_on_error=self.rec_eval_print_node_on_error, |
| 891 | ) |
| 892 | rval = self.fn(pyll_rval) |
| 893 | |
| 894 | if isinstance(rval, (float, int, np.number)): |
| 895 | dict_rval = {"loss": float(rval), "status": STATUS_OK} |
| 896 | else: |
| 897 | dict_rval = dict(rval) |
| 898 | status = dict_rval["status"] |
| 899 | if status not in STATUS_STRINGS: |
| 900 | raise InvalidResultStatus(dict_rval) |
| 901 | |
| 902 | if status == STATUS_OK: |
| 903 | # -- make sure that the loss is present and valid |
| 904 | try: |
| 905 | dict_rval["loss"] = float(dict_rval["loss"]) |
| 906 | except (TypeError, KeyError): |
| 907 | raise InvalidLoss(dict_rval) |
| 908 | |
| 909 | if attach_attachments: |
| 910 | attachments = dict_rval.pop("attachments", {}) |
| 911 | for key, val in list(attachments.items()): |
| 912 | ctrl.attachments[key] = val |
| 913 | |
| 914 | # -- don't do this here because SON-compatibility is only a requirement |
| 915 | # for trials destined for a mongodb. In-memory rvals can contain |
| 916 | # anything. |
| 917 | return dict_rval |
| 918 | |
| 919 | def evaluate_async(self, config, ctrl, attach_attachments=True): |
| 920 | """ |
no test coverage detected