class_docstr: Tests for the custom_decomps argument for devices
class_docstr_tok: ["Tests","for","the","custom_decomps","argument","for","devices"]
docstr: Test that the set_decomposition context manager works for the new device API.
docstr_tok: ["Test","that","the","set_decomposition","context","manager","works","for","the","new","device","API","."]
code: def test_custom_decomp_in_separate_context(self, mocker):
      """Test that the set_decomposition context manager works for the new device API."""
  
      # pylint:disable=protected-access
  
      dev = qml.device("default.qubit", wires=2)
      spy = mocker.spy(dev, "execute")
  
      @qml.qnode(dev, expansion_strategy="device")
      def circuit():
          qml.CNOT(wires=[0, 1])
          return qml.expval(qml.PauliZ(wires=0))
  
      # Initial test
      _ = circuit()
  
      tape = spy.call_args_list[0][0][0][0]
      assert len(tape.operations) == 1
      assert tape.operations[0].name == "CNOT"
  
      assert dev.preprocess()[0][2].transform.__name__ == "decompose"
      assert (
          dev.preprocess()[0][2].kwargs.get("decomposer", None) is None
      )
  
      # Test within the context manager
      with qml.transforms.set_decomposition(
          {qml.CNOT: custom_cnot}, dev
      ):
          _ = circuit()
  
          assert (
              dev.preprocess()[0][2].transform.__name__ == "decompose"
          )
          assert (
              dev.preprocess()[0][2].kwargs.get("decomposer", None)
              is not None
          )
  
      tape = spy.call_args_list[1][0][0][0]
      ops_in_context = tape.operations
      assert len(ops_in_context) == 3
      assert ops_in_context[0].name == "Hadamard"
      assert ops_in_context[1].name == "CZ"
      assert ops_in_context[2].name == "Hadamard"
  
      # Check that afterwards, the device has gone back to normal
      _ = circuit()
  
      tape = spy.call_args_list[2][0][0][0]
      ops_in_context = tape.operations
      assert len(tape.operations) == 1
      assert tape.operations[0].name == "CNOT"
      assert dev.preprocess()[0][2].transform.__name__ == "decompose"
      assert (
          dev.preprocess()[0][2].kwargs.get("decomposer", None) is None
      )
  
imports: import pytest
  import numpy
  import pennylane
  from pennylane.wires import Wires
label_desc: Use image node_id 14 for calling the TestCreateCustomDecompExpandFn obj's underlying member method code with example usage: obj.test_custom_decomp_in_separate_context(mocker) and returns: qml