code: def saveAndLoadNetwork(network):
      # Save network
      proto1 = NetworkProto_capnp.NetworkProto.new_message()
      network.write(proto1)
  
      with tempfile.TemporaryFile() as f:
          proto1.write(f)
          f.seek(0)
  
          # Load network
          proto2 = NetworkProto_capnp.NetworkProto.read(f)
          loadedNetwork = Network.read(proto2)
  
          # Set loaded network's datasource
          sensor = network.regions["sensor"].getSelf()
          loadedSensor = loadedNetwork.regions["sensor"].getSelf()
          loadedSensor.dataSource = sensor.dataSource
  
          # Initialize loaded network
          loadedNetwork.initialize()
  
      return loadedNetwork
  
file_path: nupic-legacy/tests/integration/nupic/engine/network_creation_common.py
imports: import copy
  import csv
  import json
  import os
  import tempfile
  from pkg_resources import resource_filename
  from nupic.data.file_record_stream import FileRecordStream
  from nupic.engine import Network
  from nupic.encoders import MultiEncoder, ScalarEncoder, DateEncoder
  from nupic.regions.record_sensor import RecordSensor
  from nupic.regions.sp_region import SPRegion
  from nupic.regions.tm_region import TMRegion
label_desc: Use image node_id 3 for calling a global function with example usage: saveAndLoadNetwork(network) and returns: loadedNetwork