def full_execution(midi_files, output_tag, total_epochs, batch_size, sequence_length, temperature, offset_adj): # epoch_stops = 1 # epoch_count = 0 weight_file = None note_file = fxn.convert_midis_to_notes(midi_files, output_tag) epochs = total_epochs with open(note_file, 'rb') as filepath: notes = pickle.load(filepath) network_input, network_output, n_patterns, n_vocab, pitchnames = fxn.prepare_sequences( notes, sequence_length) network_input_r, network_output_r = fxn.reshape_for_training( network_input, network_output, sequence_length) # while epoch_count <= total_epochs: # epochs = epoch_stops # model = fxn.create_network(network_input_r, n_vocab, weight_file) model, weight_file, history = fxn.train_model(model, network_input_r, network_output_r, epochs, batch_size, output_tag, sequence_length) normalized_input = fxn.reshape_for_creation(network_input, n_patterns, sequence_length, n_vocab) model = fxn.create_network(normalized_input, n_vocab, weight_file) prediction_output = fxn.generate_notes(model, network_input, pitchnames, sequence_length, notes_generated, n_vocab, temperature) output_notes = fxn.create_midi(prediction_output, output_tag, sequence_length, offset_adj) # epoch_count += epoch_stops return output_notes, history, weight_file
def main(): global count # Use a single, persistent session session = requests.Session() # Create new network and enable VLANs name = os.path.basename(__file__)[:-3] net_id = create_network(api_key, org_id, name, session) if not net_id: sys.exit( 'Exiting script; please check your API key and org ID in the login.py file.' ) success = enable_vlans(api_key, net_id) if not success: sys.exit('Exiting script due to error with enabling VLANs.') # API resource endpoint & headers url = f'https://api.meraki.com/api/v0/organizations/{org_id}/actionBatches' headers = { 'X-Cisco-Meraki-API-Key': api_key, 'Content-Type': 'application/json' } # Asynchronous action batch payload = {'confirmed': True, 'synchronous': False, 'actions': []} # Loop to create payload of VLANs for x in range(1, 100): vlan = str(x).zfill(2) body = { 'id': f'1{vlan}', 'name': f'{name} - {vlan}', 'subnet': f'10.0.{x}.0/24', 'applianceIp': f'10.0.{x}.1' } resource = f'/networks/{net_id}/vlans' operation = 'create' action = {'resource': resource, 'operation': operation, 'body': body} payload['actions'].append(action) # Dashboard API call response = session.post(url, headers=headers, data=json.dumps(payload)) if not response.ok: sys.exit(f'Exiting script due to error: {response.text}') action_batch = response.json()['id'] print( f'Successfully created asynchronous action batch with ID {action_batch}' ) # Check status of API call until completed while True: num_completed = check_completion(session, action_batch) if num_completed > 0: count += num_completed break else: print('Still processing...')
async def main(): global count # Use a single, persistent session session = requests.Session() # Create new network and enable VLANs name = os.path.basename(__file__)[:-3] net_id = create_network(api_key, org_id, name, session) if not net_id: sys.exit( 'Exiting script; please check your API key and org ID in the login.py file.' ) success = enable_vlans(api_key, net_id) if not success: sys.exit('Exiting script due to error with enabling VLANs.') # API resource endpoint & headers url = f'https://api.meraki.com/api/v0/networks/{net_id}/vlans' headers = { 'X-Cisco-Meraki-API-Key': api_key, 'Content-Type': 'application/json' } # Loop to create VLANs count = 0 payloads_to_post = [] for x in range(1, 100): vlan = str(x).zfill(2) payload = { 'id': f'1{vlan}', 'name': f'{name} - {vlan}', 'subnet': f'10.0.{x}.0/24', 'applianceIp': f'10.0.{x}.1' } payloads_to_post.append(payload) # Use asynchronous calls with one thread with ThreadPoolExecutor(max_workers=3) as executor: loop = asyncio.get_event_loop() tasks = [ loop.run_in_executor( executor, post, *(session, url, headers, payload ) # Allows us to pass in multiple arguments to `post` ) for payload in payloads_to_post ] for response in await asyncio.gather(*tasks): pass
def main(): global count # Use a single, persistent session session = requests.Session() # Create new network and enable VLANs name = os.path.basename(__file__)[:-3] net_id = create_network(api_key, org_id, name, session) if not net_id: sys.exit( 'Exiting script; please check your API key and org ID in the login.py file.' ) success = enable_vlans(api_key, net_id) if not success: sys.exit('Exiting script due to error with enabling VLANs.') # API resource endpoint & headers url = f'https://api.meraki.com/api/v0/networks/{net_id}/vlans' headers = { 'X-Cisco-Meraki-API-Key': api_key, 'Content-Type': 'application/json' } # Loop to create VLANs for x in range(1, 100): vlan = str(x).zfill(2) payload = { 'id': f'1{vlan}', 'name': f'{name} - {vlan}', 'subnet': f'10.0.{x}.0/24', 'applianceIp': f'10.0.{x}.1' } # Dashboard API call response = session.post(url, headers=headers, data=json.dumps(payload)) if response.ok: print(f'Created VLAN 1{vlan}') count += 1 else: print(f'{response.status_code} - {response.text}')
def main(): global count # Use a single, persistent session session = requests.Session() # Create new network and enable VLANs name = os.path.basename(__file__)[:-3] net_id = create_network(api_key, org_id, name, session) if not net_id: sys.exit( 'Exiting script; please check your API key and org ID in the login.py file.' ) success = enable_vlans(api_key, net_id) if not success: sys.exit('Exiting script due to error with enabling VLANs.') # API resource endpoint & headers url = f'https://api.meraki.com/api/v0/organizations/{org_id}/actionBatches' headers = { 'X-Cisco-Meraki-API-Key': api_key, 'Content-Type': 'application/json' } # Synchronous action batches, each up to 20 actions payload = [] for _ in range(5): payload.append( dict({ 'confirmed': True, 'synchronous': True, 'actions': [] })) # Loop to create payload of VLANs for x in range(1, 100): vlan = str(x).zfill(2) body = { 'id': f'7{vlan}', 'name': f'7_action2 - {vlan}', 'subnet': f'10.7.{x}.0/24', 'applianceIp': f'10.7.{x}.1' } resource = f'/networks/{net_id}/vlans' operation = 'create' action = {'resource': resource, 'operation': operation, 'body': body} payload[int(x / 20)]['actions'].append(action) for p in payload: response = session.post(url, data=json.dumps(p), headers=headers) action_batch = response.json() if action_batch['status']['completed']: print( f'Successfully completed synchronous action batch with ID {action_batch["id"]}' ) count += len(action_batch['actions']) elif action_batch['status']['failed']: print( f'Failed action batch with ID {action_batch["id"]} and errors: {action_batch["status"]["errors"]}' ) else: print('Ran into some other error')