class_docstr: Model of a Boolean classifier of positive/negative cross-product of input features and weights
class_docstr_tok: ["Model","of","a","Boolean","classifier","of","positive\/negative","cross-product","of","input","features","and","weights"]
code: def train_and_compare_model(
      self, parallelize: bool, multiprocessing: bool = True
  ):
      num_points = 10000
      num_features = 100
      max_num_epochs = 50
      random_seed = 1234  # None to seed from clock
      training_data, validation_data = self.__get_data(
          num_points, num_features, random_seed=random_seed
      )
  
      with tempfile.TemporaryDirectory() as dir:
          model_file = Path(dir) / "testModel.pkl.gz"
  
          model = SimpleRegressionModel()
          trainer = ModelTrainer(
              model, model_file, max_num_epochs=max_num_epochs
          )
          trainer.train(
              training_data,
              validation_data,
              parallelize=parallelize,
              use_multiprocessing=multiprocessing,
          )
          model_acc_1 = model.compute_accuracy(
              trainer.neural_module,
              iter(validation_data),
              parallelize,
              use_multiprocessing=multiprocessing,
          )
  
          model, trained_network = SimpleRegressionModel.restore_model(
              model_file
          )
          trained_model_acc = model.compute_accuracy(
              trained_network,
              iter(validation_data),
              parallelize,
              use_multiprocessing=multiprocessing,
          )
          self.assertGreater(
              trained_model_acc,
              0.95,
              f"Model achieves too low accuracy, {trained_model_acc:%}",
          )
  
          self.assertAlmostEqual(
              trained_model_acc,
              model_acc_1,
              places=3,
              msg=f"Accuracy before and after loading does not match: {trained_model_acc} vs {model_acc_1}",
          )
  
file_path: ptgnn/ptgnn/tests/simplemodel/test_model.py
imports: import tempfile
  import unittest
  from pathlib import Path
  from typing import List, Optional, Tuple
  from ptgnn.baseneuralmodel import ModelTrainer
  from ptgnn.tests.simplemodel.data import SampleDatapoint, SyntheticData
  from ptgnn.tests.simplemodel.model import SimpleRegressionModel
label_desc: Use image node_id 5 for calling the TestPytorchModel obj's underlying member method code with example usage: obj.train_and_compare_model(parallelize, multiprocessing) without return types