code: def test_PairwiseModelBridge(self, mock_init):
      # Test _convert_observations
      pmb = PairwiseModelBridge(
          # pyre-fixme[6]: For 1st param expected `Experiment` but got `None`.
          experiment=None,
          # pyre-fixme[6]: For 2nd param expected `SearchSpace` but got `None`.
          search_space=None,
          # pyre-fixme[6]: For 3rd param expected `Data` but got `None`.
          data=None,
          # pyre-fixme[6]: For 4th param expected `TorchModel` but got `None`.
          model=None,
          transforms=[],
          torch_dtype=None,
          torch_device=None,
      )
  
      observation_data = [
          ObservationData(
              metric_names=["pairwise_pref_query"],
              means=np.array([0]),
              covariance=np.array([[np.nan]]),
          ),
          ObservationData(
              metric_names=["pairwise_pref_query"],
              means=np.array([1]),
              covariance=np.array([[np.nan]]),
          ),
      ]
      observation_features = [
          ObservationFeatures(
              parameters={"y1": 0.1, "y2": 0.2}, trial_index=0
          ),
          ObservationFeatures(
              parameters={"y1": 0.3, "y2": 0.4}, trial_index=0
          ),
      ]
      observation_features_with_metadata = [
          ObservationFeatures(
              parameters={"y1": 0.1, "y2": 0.2}, trial_index=0
          ),
          ObservationFeatures(
              parameters={"y1": 0.3, "y2": 0.4},
              trial_index=0,
              metadata={"metadata_key": "metadata_val"},
          ),
      ]
      parameters = ["y1", "y2"]
      outcomes = ["pairwise_pref_query"]
  
      datasets, _, candidate_metadata = pmb._convert_observations(
          observation_data=observation_data,
          observation_features=observation_features,
          outcomes=outcomes,
          parameters=parameters,
          search_space_digest=None,
      )
      self.assertTrue(len(datasets) == 1)
      self.assertTrue(isinstance(datasets[0], RankingDataset))
      self.assertTrue(candidate_metadata is None)
  
      datasets, _, candidate_metadata = pmb._convert_observations(
          observation_data=observation_data,
          observation_features=observation_features_with_metadata,
          outcomes=outcomes,
          parameters=parameters,
          search_space_digest=None,
      )
      self.assertTrue(len(datasets) == 1)
      self.assertTrue(isinstance(datasets[0], RankingDataset))
      self.assertTrue(candidate_metadata is not None)
  
      # Test individual helper methods
      X = torch.tensor(
          [
              [1.0, 2.0, 3.0],
              [2.0, 3.0, 4.0],
              [1.0, 2.0, 3.0],
              [2.1, 3.1, 4.1],
          ]
      )
      Y = torch.tensor([[1, 0, 0, 1]])
      expected_X = torch.tensor(
          [[1.0, 2.0, 3.0], [2.0, 3.0, 4.0], [2.1, 3.1, 4.1]]
      )
      ordered_Y = torch.tensor([[0, 1], [3, 2]])
      expected_Y = torch.tensor([[0, 1], [2, 0]])
  
      # `_binary_pref_to_comp_pair`.
      comp_pair_Y = _binary_pref_to_comp_pair(Y=Y)
      self.assertTrue(torch.equal(comp_pair_Y, ordered_Y))
  
      # test `_binary_pref_to_comp_pair` with invalid data
      bad_Y = torch.tensor([[1, 1, 0, 0]])
      with self.assertRaises(ValueError):
          _binary_pref_to_comp_pair(Y=bad_Y)
  
      # `_consolidate_comparisons`.
      consolidated_X, consolidated_Y = _consolidate_comparisons(
          X=X, Y=comp_pair_Y
      )
      self.assertTrue(torch.equal(consolidated_X, expected_X))
      self.assertTrue(torch.equal(consolidated_Y, expected_Y))
  
      with self.assertRaises(ValueError):
          _consolidate_comparisons(
              X=X.expand(2, *X.shape),
              Y=comp_pair_Y.expand(2, *comp_pair_Y.shape),
          )
  
file_path: Ax/ax/modelbridge/tests/test_pairwise_modelbridge.py
imports: from unittest import mock
  import numpy
  import torch
  from ax.core.observation import ObservationData, ObservationFeatures
  from ax.modelbridge.base import ModelBridge
  from ax.modelbridge.pairwise import _binary_pref_to_comp_pair, _consolidate_comparisons, PairwiseModelBridge
  from ax.utils.common.testutils import TestCase
  from botorch.utils.datasets import RankingDataset
label_desc: Use image node_id 1 for calling the PairwiseModelBridgeTest obj's underlying member method code with example usage: obj.test_PairwiseModelBridge(mock_init) without return types