def METHOD_NAME(param, key, shots=10000):
    # expectation with shot noise
    # ps, w: H = \sum_i w_i ps_i
    # describing the system Hamiltonian as a weighted sum of Pauli string
    c = generate_circuit(param, g, n, nlayers)
    loss = 0
    s = c.state()
    mc = tc.quantum.measurement_counts(
        s,
        counts=shots,
        format="sample_bin",
        random_generator=key,
        jittable=True,
        is_prob=False,
    )
    for ps, w in zip(pss, ws):
        loss += w * tc.quantum.correlation_from_samples(ps2z(ps), mc, c._nqubits)
    return K.real(loss)