To debug string. Args: throw_on_error (bool): raise Value error when any of required fields is not set. with_details (bool): True if more details about variables and parameters, e.g., :code:`trainable`, :code:`optimize_attr`, need to print. Return
(self, throw_on_error, with_details=False)
| 6469 | return program_str |
| 6470 | |
| 6471 | def to_string(self, throw_on_error, with_details=False): |
| 6472 | """ |
| 6473 | To debug string. |
| 6474 | |
| 6475 | Args: |
| 6476 | |
| 6477 | throw_on_error (bool): raise Value error when any of required fields is not set. |
| 6478 | |
| 6479 | with_details (bool): True if more details about variables and parameters, e.g., :code:`trainable`, :code:`optimize_attr`, need to print. |
| 6480 | |
| 6481 | Returns: |
| 6482 | str: The debug string describe current Program. |
| 6483 | |
| 6484 | Raises: |
| 6485 | ValueError: If any of required fields is not set and throw_on_error is True. |
| 6486 | |
| 6487 | Examples: |
| 6488 | .. code-block:: pycon |
| 6489 | |
| 6490 | >>> import paddle |
| 6491 | >>> import paddle.static as static |
| 6492 | |
| 6493 | >>> paddle.enable_static() |
| 6494 | |
| 6495 | >>> prog = static.default_main_program() |
| 6496 | >>> x = static.data(name="X", shape=[2, 3], dtype="float32") |
| 6497 | >>> pred = static.nn.fc(x, size=3) |
| 6498 | >>> prog_string = prog.to_string(throw_on_error=True, with_details=False) |
| 6499 | >>> prog_string_with_details = prog.to_string(throw_on_error=False, with_details=True) |
| 6500 | >>> print("program string without detail: {}".format(prog_string)) |
| 6501 | >>> print("program string with detail: {}".format(prog_string_with_details)) |
| 6502 | """ |
| 6503 | assert isinstance(throw_on_error, bool), ( |
| 6504 | f"The type of throw_on_error parameter is wrong, expected bool, but received {type(throw_on_error)}." |
| 6505 | ) |
| 6506 | assert isinstance(with_details, bool), ( |
| 6507 | f"The type of with_details parameter is wrong, expected bool, but received {type(with_details)}." |
| 6508 | ) |
| 6509 | |
| 6510 | if with_details: |
| 6511 | res_str = "" |
| 6512 | for block in self.blocks: |
| 6513 | res_str += block.to_string(throw_on_error, with_details) |
| 6514 | protostr = self.desc.serialize_to_string() |
| 6515 | proto = framework_pb2.ProgramDesc.FromString(bytes(protostr)) |
| 6516 | res_str += ( |
| 6517 | "version {\n " |
| 6518 | + textwrap.indent( |
| 6519 | _debug_string_(proto.version, throw_on_error), " " |
| 6520 | ) |
| 6521 | + "}\n" |
| 6522 | ) |
| 6523 | res_str += ( |
| 6524 | "op_version_map {\n " |
| 6525 | + textwrap.indent( |
| 6526 | _debug_string_(proto.op_version_map, throw_on_error), " " |
| 6527 | ) |
| 6528 | + "}\n" |
nothing calls this directly
no test coverage detected