in the below code i cannot complete the entire dataset generation for the range of 1000 samples with in a single day, so i need the below code to adapt pause and play options, i need to shutdown the code today and need to continue to run the code on tomorrow from where the number of samples ends on today. please modify the code accordingly

def pre_training_dataset_generation(env):
    """Generate pre-training dataset with manual tuning data"""
    env.connect_to_simulator()  # Ensure simulator is connected before dataset generation

    dataset = []

    # Initialize CSV file and writer
    with open('transistor_data.csv', mode='w', newline='') as csvfile:
        fieldnames = ['L1', 'L3', 'L5', 'L6', 'L7', 'W1', 'W3', 'W5', 'W6', 'W7',
                      'Ib', 'Cc', 'Vc', 'M1', 'M2', 'M3', 'M4', 'M5', 'M8', 'M6', 
                      'M7', 'Area', 'PowerDissipation', 'SlewRate', 'Gain', 'Bandwidth3dB', 
                      'UnityGainFreq', 'PhaseMargin']
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
        writer.writeheader()

        for _ in range(1000):  # Create 1000 samples
            sample_found = False

            while not sample_found:
                raw_actions = np.random.uniform(low=env.bounds_low, high=env.bounds_high)  # Random initial actions
                iteration = 0
                
                while iteration < env.max_iterations:
                    transistor_regions, saturation_condition, performance_metrics = env.simulator.run_simulation(raw_actions)

                    # Write results directly to CSV
                    writer.writerow({
                        'L1': raw_actions[0], 'L3': raw_actions[1], 'L5': raw_actions[2], 'L6': raw_actions[3], 'L7': raw_actions[4],
                        'W1': raw_actions[5], 'W3': raw_actions[6], 'W5': raw_actions[7], 'W6': raw_actions[8], 'W7': raw_actions[9],
                        'Ib': raw_actions[10], 'Cc': raw_actions[11], 'Vc': raw_actions[12],
                        'M1': transistor_regions.get('M1', None), 'M2': transistor_regions.get('M2', None), 'M3': transistor_regions.get('M3', None),
                        'M4': transistor_regions.get('M4', None), 'M5': transistor_regions.get('M5', None), 'M8': transistor_regions.get('M8', None),
                        'M6': transistor_regions.get('M6', None), 'M7': transistor_regions.get('M7', None),
                        'Area': performance_metrics.get('Area', None), 'PowerDissipation': performance_metrics.get('PowerDissipation', None),
                        'SlewRate': performance_metrics.get('SlewRate', None), 'Gain': performance_metrics.get('Gain', None),
                        'Bandwidth3dB': performance_metrics.get('Bandwidth3dB', None), 'UnityGainFreq': performance_metrics.get('UnityGainFreq', None),
                        'PhaseMargin': performance_metrics.get('PhaseMargin', None)
                    })

                    if all(region == 2 for region in transistor_regions.values()): 
                        node_features_tensor, edge_feature_tensor, edge_index = netlist_to_graph(env.netlist_content, raw_actions, transistor_regions)
                        state = (torch.tensor(node_features_tensor, dtype=torch.float32), torch.tensor(edge_feature_tensor, dtype=torch.float32), torch.tensor(edge_index, dtype=torch.long))
                        actions = torch.tensor(raw_actions, dtype=torch.float32)
                        dataset.append((state, actions))
                        sample_found = True
                        break

                    # Try adjusting raw actions and continue iterations
                    raw_actions = env.adjust_raw_actions_value(raw_actions, transistor_regions)
                    print("transistor_regions", transistor_regions)
                    print("iteration count", iteration)
                    
                    iteration += 1

    env.disconnect_from_simulator()  # Optionally disconnect after dataset generation
    
    return dataset