code: def get_state_cost_fn(circuit):
      """Get the scalar cost function dependent on the output state"""
  
      def cost_fn(x):
          res = circuit(x)
          probs = qml.math.abs(res) ** 2
          return probs[0]
  
      return cost_fn
  
imports: import pytest
  import pennylane
  from pennylane import numpy
  from pennylane import QuantumFunctionError
  from pennylane.measurements import Probability, Expectation, Variance, Sample, VnEntropy, MutualInfo
  from pennylane.measurements.measurements import ObservableReturnTypes
label_desc: Use image node_id 3 for calling a global function with example usage: get_state_cost_fn(circuit) and returns: cost_fn, probs