To debug string. Args: throw_on_error(bool): raise exception when self is not initialized when throw_on_error is True with_details(bool): more details about variables and parameters (e.g. trainable, optimize_attr, ...) will be
(self, throw_on_error, with_details=False)
| 7751 | return self._to_readable_code() |
| 7752 | |
| 7753 | def to_string(self, throw_on_error, with_details=False): |
| 7754 | """ |
| 7755 | To debug string. |
| 7756 | |
| 7757 | Args: |
| 7758 | throw_on_error(bool): raise exception when self is not initialized |
| 7759 | when throw_on_error is True |
| 7760 | with_details(bool): more details about variables and parameters |
| 7761 | (e.g. trainable, optimize_attr, ...) will be printed when with_details is True |
| 7762 | |
| 7763 | Returns(str): The debug string. |
| 7764 | |
| 7765 | Examples: |
| 7766 | .. code-block:: pycon |
| 7767 | |
| 7768 | >>> import paddle |
| 7769 | >>> paddle.enable_static() |
| 7770 | >>> prog = paddle.static.default_main_program() |
| 7771 | >>> rlt = paddle.static.data("fake_data", shape=[-1, 1, 1], dtype='float32') |
| 7772 | >>> debug_str = prog.to_string(throw_on_error=True, with_details=False) |
| 7773 | >>> print(debug_str) |
| 7774 | """ |
| 7775 | assert isinstance(throw_on_error, bool) and isinstance( |
| 7776 | with_details, bool |
| 7777 | ) |
| 7778 | if with_details: |
| 7779 | res_str = Variable.to_string(self, throw_on_error, True) |
| 7780 | additional_attr = ( |
| 7781 | "trainable", |
| 7782 | "optimize_attr", |
| 7783 | "regularizer", |
| 7784 | "do_model_average", |
| 7785 | "need_clip", |
| 7786 | ) |
| 7787 | for attr_name in additional_attr: |
| 7788 | res_str += f"{attr_name}: {getattr(self, attr_name)}\n" |
| 7789 | else: |
| 7790 | res_str = Variable.to_string(self, throw_on_error, False) |
| 7791 | return res_str |
| 7792 | |
| 7793 | __repr__ = __str__ |
| 7794 |