class_docstr: Unit tests for policy gradient.
class_docstr_tok: ["Unit","tests","for","policy","gradient","."]
code: def test_init_from_existing_model(self, mock_parameters):
      action_space = spaces.Discrete(3)
      observation_space = spaces.Box(
          np.array([-1.2, -0.07]), np.array([0.6, 0.07])
      )
      mock_parameters.return_value.policy_representation = "nn"
      mock_parameters.return_value.policy_network_hidden_layers = "[2]"
      mock_parameters.return_value.initial_policy_network = (
          "tests/data/initial_policy_network.dnn"
      )
      mock_parameters.return_value.preprocessing = ""
  
      sut = ActorCritic("", observation_space, action_space)
  
      self.assertEqual(sut._num_actions, 3)
      self.assertIsNone(sut._num_states)
      self.assertEqual(sut._shape_of_inputs, (2,))
      self.assertFalse(sut._discrete_observation_space)
      self.assertIsNone(sut._space_discretizer)
      self.assertIsNone(sut._preprocessor)
  
      # Incompatible network structure.
      mock_parameters.return_value.policy_network_hidden_layers = "[]"
      self.assertRaises(
          Exception, ActorCritic, "", observation_space, action_space
      )
  
      # Incompatible action space.
      mock_parameters.return_value.policy_network_hidden_layers = "[2]"
      action_space = spaces.Discrete(2)
      self.assertRaises(
          ValueError, ActorCritic, "", observation_space, action_space
      )
  
      # Incompatible observation space.
      action_space = spaces.Discrete(3)
      observation_space = spaces.Box(
          np.array([-1.2, -0.07, -1.0]), np.array([0.6, 0.07, 1.0])
      )
      self.assertRaises(
          ValueError, ActorCritic, "", observation_space, action_space
      )
  
imports: import unittest
  import cntk.contrib.deeprl.tests.spaces
  import numpy
  from cntk.contrib.deeprl.agent.policy_gradient import ActorCritic
  from cntk.layers import Dense
  from cntk.losses import cross_entropy_with_softmax
  from cntk.ops import input_variable, placeholder
label_desc: Use image node_id 2 for calling the PolicyGradientTest obj's underlying member method code with example usage: obj.test_init_from_existing_model(mock_parameters) without return types