Compares two `GraphDump` monitors and returns differences. Args: other_dump: Another `GraphDump` monitor. step: `int`, step to compare on. atol: `float`, absolute tolerance in comparison of floating arrays. Returns: Returns tuple: matched: `list` of keys tha
(self, other_dump, step, atol=1e-06)
| 913 | |
| 914 | # TODO(ptucker): Handle keys that are in one but not the other. |
| 915 | def compare(self, other_dump, step, atol=1e-06): |
| 916 | """Compares two `GraphDump` monitors and returns differences. |
| 917 | |
| 918 | Args: |
| 919 | other_dump: Another `GraphDump` monitor. |
| 920 | step: `int`, step to compare on. |
| 921 | atol: `float`, absolute tolerance in comparison of floating arrays. |
| 922 | |
| 923 | Returns: |
| 924 | Returns tuple: |
| 925 | matched: `list` of keys that matched. |
| 926 | non_matched: `dict` of keys to tuple of 2 mismatched values. |
| 927 | |
| 928 | Raises: |
| 929 | ValueError: if a key in `data` is missing from `other_dump` at `step`. |
| 930 | """ |
| 931 | non_matched = {} |
| 932 | matched = [] |
| 933 | this_output = self.data[step] if step in self.data else {} |
| 934 | other_output = other_dump.data[step] if step in other_dump.data else {} |
| 935 | for key in this_output: |
| 936 | if not isinstance(key, six.string_types): |
| 937 | continue |
| 938 | if key not in other_output: |
| 939 | raise ValueError("%s missing at step %s.", (key, step)) |
| 940 | value1 = _extract_output(this_output, key) |
| 941 | value2 = _extract_output(other_output, key) |
| 942 | if isinstance(value1, str): |
| 943 | continue |
| 944 | if isinstance(value1, np.ndarray): |
| 945 | if not np.allclose(value1, value2, atol=atol): |
| 946 | non_matched[key] = value1 - value2 |
| 947 | else: |
| 948 | matched.append(key) |
| 949 | else: |
| 950 | if value1 != value2: |
| 951 | non_matched[key] = (value1, value2) |
| 952 | else: |
| 953 | matched.append(key) |
| 954 | return matched, non_matched |
| 955 | |
| 956 | |
| 957 | class ExportMonitor(EveryN): |