class_docstr: Unit tests for transpile function
class_docstr_tok: ["Unit","tests","for","transpile","function"]
docstr: Test that if a device is provided and a state is measured, then the state will be transposed during post processing.
docstr_tok: ["Test","that","if","a","device","is","provided","and","a","state","is","measured",",","then","the","state","will","be","transposed","during","post","processing","."]
code: def test_transpile_state_with_device(self):
      """Test that if a device is provided and a state is measured, then the state will be transposed during post processing."""
  
      dev = qml.device("default.qubit", wires=(0, 1, 2))
  
      tape = qml.tape.QuantumScript(
          [qml.PauliX(0), qml.CNOT(wires=(0, 2))], [qml.state()]
      )
      batch, fn = qml.transforms.transpile(
          tape, coupling_map=[(0, 1), (1, 2)], device=dev
      )
  
      original_mat = np.arange(8)
      new_mat = fn((original_mat,))
      expected_new_mat = np.swapaxes(
          np.reshape(original_mat, [2, 2, 2]), 1, 2
      ).flatten()
      assert qml.math.allclose(new_mat, expected_new_mat)
  
      assert batch[0][0] == qml.PauliX(0)
      assert batch[0][1] == qml.SWAP((1, 2))
      assert batch[0][2] == qml.CNOT((0, 1))
      assert batch[0][3] == qml.state()
  
      pre, post = dev.preprocess()[0]((tape,))
      original_results = post(dev.execute(pre))
      transformed_results = fn(dev.execute(batch))
      assert qml.math.allclose(original_results, transformed_results)
  
imports: from math import isclose
  import pytest
  from pennylane import numpy
  import pennylane
  from pennylane.transforms.transpile import transpile
label_desc: Use image node_id 13 for calling the TestTranspile obj's underlying member method code with example usage: obj.test_transpile_state_with_device() without return types