How to Get Runtime and Predcition Value in ldc_2d.py?

Using the ldc_2d.py as a base case, how can I do the following:

(i) Get a u value (the output of the NN) on a specific x and y value?
(ii) Get the runtime (prediction time) on a test dataset?

Hello @ngeneva, are you able to help me with this? Especially on part (I), are there specific methods I need to call to get the predictions from the specific input values?

1 Like

I managed to reconstruct the network using the saved pth file, i.e., flow_network.0.pth in your demo.

Can you elaborate, please?

These are PyTorch checkpoints, so one could use Modulus’ built in eval functionality or instead manually load the checkpoint using the Arch class load function in a custom script.

So for ldc you could do something like:

flow_net = instantiate_arch(
        input_keys=[Key("x"), Key("y")],
        output_keys=[Key("u"), Key("v"), Key("p")],
        cfg=cfg.arch.fully_connected,
    )

flow_net.load("<Directory of checkpoint file>")

or if you want to use the PyTorch APIs:

flow_net = instantiate_arch(
        input_keys=[Key("x"), Key("y")],
        output_keys=[Key("u"), Key("v"), Key("p")],
        cfg=cfg.arch.fully_connected,
    )

flow_net.load_state_dict(torch.load("<File path to checkpoint file>"), map_location="cpu (or cuda:0)")

Example here for a different example.