class_docstr: Simulate distributed training.
class_docstr_tok: ["Simulate","distributed","training","."]
docstr: Run the distributed training process on a single machine.
  
  For each worker i:
      1. The i-th partition is saved as train{i}.txt.
      2. A random port is assigned for training.
      3. A configuration file train{i}.conf is created.
      4. The lightgbm binary is called with config=train{i}.conf in another thread.
      5. The trained model is saved as model{i}.txt. Each model file only differs in data and local_listen_port.
  The whole training set is saved as train.txt.
docstr_tok: ["Run","the","distributed","training","process","on","a","single","machine",".","For","each","worker","i",":","1",".","The","i-th","partition","is","saved","as","train","{","i","}",".txt",".","2",".","A","random","port","is","assigned","for","training",".","3",".","A","configuration","file","train","{","i","}",".conf","is","created",".","4",".","The","lightgbm","binary","is","called","with","config=train","{","i","}",".conf","in","another","thread",".","5",".","The","trained","model","is","saved","as","model","{","i","}",".txt",".","Each","model","file","only","differs","in","data","and","local_listen_port",".","The","whole","training","set","is","saved","as","train.txt","."]
code: def fit(
      self, partitions: List[np.ndarray], train_config: Dict
  ) -> None:
      """Run the distributed training process on a single machine.
  
      For each worker i:
          1. The i-th partition is saved as train{i}.txt.
          2. A random port is assigned for training.
          3. A configuration file train{i}.conf is created.
          4. The lightgbm binary is called with config=train{i}.conf in another thread.
          5. The trained model is saved as model{i}.txt. Each model file only differs in data and local_listen_port.
      The whole training set is saved as train.txt.
      """
      self.train_config = copy.deepcopy(self.default_train_config)
      self.train_config.update(train_config)
      self.n_workers = self.train_config["num_machines"]
      self._set_ports()
      self._write_data(partitions)
      self.label_ = np.hstack(
          [partition[:, 0] for partition in partitions]
      )
      futures = []
      with ThreadPoolExecutor(max_workers=self.n_workers) as executor:
          for i in range(self.n_workers):
              self.write_train_config(i)
              train_future = executor.submit(self.worker_train, i)
              futures.append(train_future)
          results = [f.result() for f in futures]
      for result in results:
          if result.returncode != 0:
              raise RuntimeError("Error in training")
  
imports: import copy
  import io
  import socket
  import subprocess
  from concurrent.futures import ThreadPoolExecutor
  from pathlib import Path
  from typing import Any, Dict, Generator, List
  import numpy
  import pytest
  from sklearn.datasets import make_blobs, make_regression
  from sklearn.metrics import accuracy_score
label_desc: Use image node_id 5 for calling the DistributedMockup obj's underlying member method code with example usage: obj.fit(partitions, train_config) without return types