code: def coordinate_sampler(indices, num_params, idx, rng=None):
      """Return a single canonical basis vector, corresponding
      to the index ``indices[idx]``. This is a sequential coordinate sampler
      that allows to exactly reproduce derivatives, instead of using SPSA in the
      intended way."""
      # pylint: disable=unused-argument
      idx = idx % len(indices)
      direction = np.zeros(num_params)
      direction[indices[idx]] = 1.0
      return direction
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.devices import DefaultQubitLegacy
  from pennylane.gradients import spsa_grad
  from pennylane.gradients.spsa_gradient import _rademacher_sampler
  from pennylane.operation import AnyWires, Observable
label_desc: Use image node_id 1 for calling a global function with example usage: coordinate_sampler(indices, num_params, idx, rng) and returns: direction