# Get gradients at the flux points

**URL:** https://pyfr.discourse.group/t/get-gradients-at-the-flux-points/1179
**Category:** Development
**Created:** [21 October 2024 14:28 UTC](https://pyfr.discourse.group/t/get-gradients-at-the-flux-points/1179 "2024-10-21T14:28:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Zhenyang](https://avatars.discourse-cdn.com/v4/letter/z/ec9cab/32.png) [@Zhenyang](https://pyfr.discourse.group/u/Zhenyang)
#### Post date: [21 October 2024 14:28 UTC](https://pyfr.discourse.group/t/get-gradients-at-the-flux-points/1179/1 "2024-10-21T14:28:16Z")

</div>

Hi,

I am using `_compute_basegrads_graph` to calculate the gradient of solution to be used in the simulation. And furthermore, I also want to get gradient at the flux points. So I simply add the following expressions in the graph:

```auto
        # Above are the same as the compute_grads_graph in baseadvecdiff/system.py
        # To calculate interpolated gradient at flux points
        g3 = self.backend.graph()

        # Interpolate these gradients to the flux points
        for l in k['eles/gradcoru_fpts']:
            g3.add(l, deps=deps(l, 'eles/gradcoru_u'))
        g3.commit()

        return g1, g2, g3

```

But it kept complaining about the KeyError as in:

```auto
  File "/scratch/zhenyang/software/Anaconda/anaconda/envs/pyfr_linsolver/lib/python3.10/site-packages/pyfr/solvers/baselinadvecdiff/system.py", line 64, in _compute_basegrads_graph
    g3.add(l, deps=deps(l, 'eles/gradcoru_u'))
  File "/scratch/zhenyang/software/Anaconda/anaconda/envs/pyfr_linsolver/lib/python3.10/site-packages/pyfr/backends/base/types.py", line 337, in add
    rdeps = [self.knodes[d] for d in adeps]
  File "/scratch/zhenyang/software/Anaconda/anaconda/envs/pyfr_linsolver/lib/python3.10/site-packages/pyfr/backends/base/types.py", line 337, in <listcomp>
    rdeps = [self.knodes[d] for d in adeps]
KeyError: <pyfr.backends.openmp.provider.OpenMPUnorderedMetaKernel object at 0x14b0829e9480>

```

Could you spot the problem with the implementation? Thanks in advance.

Regards,  
Zhenyang

---

<div class="post-metadata">

### Author: ![fdw](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fdw](https://pyfr.discourse.group/u/fdw)
#### Post date: [22 October 2024 01:55 UTC](https://pyfr.discourse.group/t/get-gradients-at-the-flux-points/1179/2 "2024-10-22T01:55:47Z")

</div>

The problem is the dependency `deps=deps(l, 'eles/gradcoru_u')`. No kernel `eles/gradcoru_u` has ever been added to the graph `g3` hence the key error when PyFR attempts to look up what it refers to.

Regards, Freddie.
