MeteoSwiss-APN / HIR

MIT License
2 stars 3 forks source link

Simple HIR example #12

Open rupertford opened 5 years ago

rupertford commented 5 years ago

It would be useful if there were an examples directory with working HIR examples. I tried pulling out the one in the documentation but this fails with ...

Traceback (most recent call last):
  File "src/python/deserializeHIR.py", line 226, in <module>
    hir.ParseFromString(args.hirfile.read())
  File "/home/rupert/proj/HIR/build/prefix/protobuf/python/google/protobuf/message.py", line 185, in ParseFromString
    self.MergeFromString(serialized)
  File "/home/rupert/proj/HIR/build/prefix/protobuf/python/google/protobuf/internal/python_message.py", line 1069, in MergeFromString
    if self._InternalParse(serialized, 0, length) != length:
  File "/home/rupert/proj/HIR/build/prefix/protobuf/python/google/protobuf/internal/python_message.py", line 1095, in InternalParse
    new_pos = local_SkipField(buffer, new_pos, end, tag_bytes)
  File "/home/rupert/proj/HIR/build/prefix/protobuf/python/google/protobuf/internal/decoder.py", line 850, in SkipField
    return WIRETYPE_TO_SKIPPER[wire_type](buffer, pos, end)
  File "/home/rupert/proj/HIR/build/prefix/protobuf/python/google/protobuf/internal/decoder.py", line 820, in _RaiseInvalidWireType
    raise _DecodeError('Tag had invalid wire type.')
google.protobuf.message.DecodeError: Tag had invalid wire type.
cosunae commented 5 years ago

Hi @rupertford

did you provided an HIR file to that example? The example is probably not protected, but it is expecting a hir file in google protobuf byte format. The example shows how to traverse the HIR specification and do something with it. In this simple case, only to pretty print the equations that were coded in HIR form. It is aim at tools that want to explore the HIR and do something with it. What you probably want to do is the opposite, i.e. generate an HIR file using the python API from a given frontend, isnt?

I will provide a simple example on how to do that. I will let you know

rupertford commented 5 years ago

Ah, my mistake. I assumed that the text of the example was actually an HIR file, so I fed that in. So, in that case, yes an example of how to generate HIR via the Python API and/or a pointer to the API definition would be great. Thanks @cosunae

cosunae commented 5 years ago

The main API is defined in the python file (autogenerated by protobuffers) gen/src/proto/HIR_pb2.py but that will be hard to look at. The API will give you access to create nodes of the HIR, insert children, etc. Where the nodes should be more formally defined in the document (notice though that the current .proto implementation and the specification document differ slightly).

However best would be If I give you an example, where I can document the steps to create it. Just need a couple of days to do it

cosunae commented 5 years ago

@rupertford you can find the examples in this

https://github.com/cosunae/dawn/tree/python_examples/examples/python

some explanation about it:

Let me know if that helps

rupertford commented 5 years ago

Thanks @cosunae. I am getting errors when I build with cmake and get nothing in the install directory. I'll email the details.