I am trying to define a my own `ExpectationMP`

and get a different energy estimation, instead of taking all states measured I want to take the k-most significant states. I tried to define my own expectation class and it did not work.

```
def find_max_diff(X_hist):
max_diff = 0
saved_k = 0
X_hist = np.sort(X_hist)[::-1]
for k in range(len(X_hist) - 1):
if X_hist[k] - X_hist[k + 1] >= max_diff:
max_diff = X_hist[k] - X_hist[k + 1]
saved_k = k
return X_hist[saved_k], X_hist[saved_k + 1]
def get_top_k_probs(X_hist):
x_k, x_k_next = find_max_diff(X_hist)
n = 0
top_k_hist = [0] * len(X_hist)
for i,v in enumerate(X_hist):
if v >= x_k:
top_k_hist[i] = v
n += v
print(f'top_k_hist: {top_k_hist}')
top_k_probs = [v / n for v in top_k_hist]
print(f'top_k_probs: {top_k_probs}')
return top_k_probs
def estimate_top_k_energy(H, X_hist):
top_k_probs = get_top_k_probs(X_hist)
return qml.math.dot(top_k_probs, qml.SparseHamiltonian(H.sparse_matrix(), cost_h.wires).eigvals().real)
class TopKEnergyEstimation(ExpectationMP):
def __init__(self, op):
super().__init__(op)
def process_counts(self, counts, wire_order):
X_hist = np.asarray(list(counts.values()))
return estimate_top_k_energy(self.obs, X_hist)
cost_h, mixer_h = qml.qaoa.cost.maxcut(G)
def circuit_wrapper(dev):
@qml.qnode(dev)
def circuit(params):
for w in dev.wires:
qml.Hadamard(wires=w)
# params[0] is gamma values for all layers
# params[1] is beta values for all layers
qml.layer(qaoa_layer, len(params[0]), params[0], params[1], cost_h=cost_h, mixer_h=mixer_h)
return TopKEnergyEstimation(cost_h)
return circuit
```

And, finally, make sure to include the versions of your packages. Specifically, show us the output of `qml.about()`

.

```
Platform info: Windows-10-10.0.19045-SP0
Python version: 3.9.12
Numpy version: 1.23.0
Scipy version: 1.8.0
Installed devices:
- default.clifford (PennyLane-0.36.0)
- default.gaussian (PennyLane-0.36.0)
- default.mixed (PennyLane-0.36.0)
- default.qubit (PennyLane-0.36.0)
- default.qubit.autograd (PennyLane-0.36.0)
- default.qubit.jax (PennyLane-0.36.0)
- default.qubit.legacy (PennyLane-0.36.0)
- default.qubit.tf (PennyLane-0.36.0)
- default.qubit.torch (PennyLane-0.36.0)
- default.qutrit (PennyLane-0.36.0)
- default.qutrit.mixed (PennyLane-0.36.0)
- null.qubit (PennyLane-0.36.0)
- lightning.qubit (PennyLane-Lightning-0.36.0)
- braket.aws.qubit (amazon-braket-pennylane-plugin-1.13.1)
- braket.local.qubit (amazon-braket-pennylane-plugin-1.13.1)
```