docstr: Test qinfo measurements with torch.
docstr_tok: ["Test","qinfo","measurements","with","torch","."]
code: def test_qinfo_torch(self):
      """Test qinfo measurements with torch."""
      import torch
  
      phi = torch.tensor(1.928, requires_grad=True)
  
      def f(x):
          qs = qml.tape.QuantumScript(
              [qml.IsingXX(x, wires=(0, 1))], self.measurements
          )
          return simulate(qs)
  
      results = f(phi)
      for val1, val2 in zip(
          results, self.expected_results(phi.detach().numpy())
      ):
          assert qml.math.allclose(val1, val2)
  
      def real_out(phi):
          return tuple(torch.real(r) for r in f(torch.real(phi)))
  
      grad_real = torch.autograd.functional.jacobian(real_out, phi)
  
      def imag_out(phi):
          return tuple(
              torch.imag(r) if torch.is_complex(r) else torch.tensor(0)
              for r in f(phi)
          )
  
      grad_imag = torch.autograd.functional.jacobian(imag_out, phi)
      grads = tuple(r + 1j * i for r, i in zip(grad_real, grad_imag))
  
      expected_grads = self.expected_grad(phi.detach().numpy())
  
      # Writing this way makes it easier to figure out which is failing
      # density 0
      assert qml.math.allclose(grads[0], expected_grads[0])
      # density 1
      assert qml.math.allclose(grads[1], expected_grads[1])
      # density both
      assert qml.math.allclose(grads[2], expected_grads[2])
      # entropy 0
      assert qml.math.allclose(grads[3], expected_grads[3])
      # entropy 1
      assert qml.math.allclose(grads[4], expected_grads[4])
      # mutual info
      assert qml.math.allclose(grads[5], expected_grads[5])
  
imports: import pytest
  import numpy
  import pennylane
  from pennylane.devices.qubit import simulate, get_final_state, measure_final_state
label_desc: Use image node_id 8 for calling the TestQInfoMeasurements obj's underlying member method code with example usage: obj.test_qinfo_torch() and returns: simulate, tuple, tuple