Skip to content

Commit

Permalink
General-purpose experiment file loading API
Browse files Browse the repository at this point in the history
  • Loading branch information
tbennun committed Feb 6, 2024
1 parent d19bec4 commit f9e43d0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions python/lbann/proto/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,21 @@ def bin2text(infile: str, outfile: str):
f.write(
google.protobuf.text_format.MessageToString(
message, use_index_order=True).encode())


def generic_load(filename: str):
"""
Loads a .protobin or .prototext file.
"""
try: # Try binary first
message = lbann_pb2.LbannPB()

# Read file
with open(filename, 'rb') as f:
message.ParseFromString(f.read())
except: # Try text
with open(filename, 'rb') as f:
message = google.protobuf.text_format.Parse(
f.read(), lbann_pb2.LbannPB())

return message

0 comments on commit f9e43d0

Please sign in to comment.