Repository: BBN-Q/Auspex

Issue:
Defer update_descriptors() until run time
Many filters are quite confused about their lot in life before the experiment has all of its parameter sweeps added. Defer calling update_descriptors() until we actually want to run.

Discussion:

Patch:
diff --git a/src/auspex/experiment.py b/src/auspex/experiment.py
index 936fa70f..6452b6f8 100644
--- a/src/auspex/experiment.py
+++ b/src/auspex/experiment.py
@@ -237,7 +237,6 @@ class Experiment(metaclass=MetaExperiment):
 
         # Run the stream init
         self.init_streams()
-        self.update_descriptors()
 
     def set_graph(self, edges):
         unique_nodes = []
@@ -248,7 +247,6 @@ class Experiment(metaclass=MetaExperiment):
                 unique_nodes.append(ee.parent)
         self.nodes = unique_nodes
         self.graph = ExperimentGraph(edges, self.loop)
-        self.update_descriptors()
 
     def init_streams(self):
         """Establish the base descriptors for any internal data streams and connectors."""
@@ -386,6 +384,9 @@ class Experiment(metaclass=MetaExperiment):
         self.instrs_connected = False
 
     def run_sweeps(self):
+        # Propagate the descriptors through the network
+        self.update_descriptors()
+
         #connect all instruments
         if not self.instrs_connected:
             self.connect_instruments()
@@ -495,7 +496,6 @@ class Experiment(metaclass=MetaExperiment):
         for oc in self.output_connectors.values():
             logger.debug("Adding axis %s to connector %s.", axis, oc.name)
             oc.descriptor.add_axis(axis)
-        self.update_descriptors()
 
     def add_sweep(self, parameters, sweep_list, refine_func=None, callback_func=None, metadata=None):
         ax = SweepAxis(parameters, sweep_list, refine_func=refine_func, callback_func=callback_func, metadata=metadata)
diff --git a/src/auspex/instruments/instrument.py b/src/auspex/instruments/instrument.py
index c00a8e5d..93874085 100644
--- a/src/auspex/instruments/instrument.py
+++ b/src/auspex/instruments/instrument.py
@@ -1,6 +1,6 @@
-# __all__ = ['Command', 'FloatCommand', 'StringCommand', 'IntCommand', 'RampCommand',
-#             'SCPICommand',
-#             'DigitizerChannel',
+# __all__ = ['Command', 'FloatCommand', 'StringCommand', 'IntCommand', 'RampCommand', 
+#             'SCPICommand', 
+#             'DigitizerChannel', 
 __all__ = ['Instrument'] # 'SCPIInstrument', 'CLibInstrument', 'MetaInstrument']
 
 import numpy as np
@@ -226,24 +226,22 @@ class SCPIInstrument(Instrument):
             # Load the dummy interface, unless we see that GPIB is in the resource string
             if any([x in self.resource_name for x in ["GPIB", "USB", "SOCKET", "hislip", "inst0", "COM"]]):
                 interface_type = "VISA"
-
+                
         try:
             if interface_type is None:
                 logger.debug("Instrument {} is using a generic instrument " +
                     "interface as none was provided.".format(self.name))
                 self.interface = Interface()
             elif interface_type == "VISA":
-                if "GPIB" in self.full_resource_name:
-                    pass
-                elif any(is_valid_ipv4(substr) for substr in self.full_resource_name.split("::")) and "TCPIP" not in self.full_resource_name:
+                if any(is_valid_ipv4(substr) for substr in self.full_resource_name.split("::")) and "TCPIP" not in self.full_resource_name:
                     # assume single NIC for now
                     self.full_resource_name = "TCPIP0::" + self.full_resource_name
                 self.interface = VisaInterface(self.full_resource_name)
                 print(self.interface._resource)
                 logger.debug("A pyVISA interface {} was created for instrument {}.".format(str(self.interface._resource), self.name))
-            elif interface_type == "Prologix":
+            elif interface_type == "Prologix":                
                 self.interface = PrologixInterface(self.full_resource_name)
-
+                    
             else:
                 raise ValueError("That interface type is not yet recognized.")
         except:


Test patch:
diff --git a/test/test_average.py b/test/test_average.py
index 5c015bd1..93bf241d 100644
--- a/test/test_average.py
+++ b/test/test_average.py
@@ -136,7 +136,7 @@ class AverageTestCase(unittest.TestCase):
         exp             = TestExperiment()
         printer_partial = Print(name="Partial")
         printer_final   = Print(name="Final")
-        avgr            = Averager(name="TestAverager")
+        avgr            = Averager(name="TestAverager", axis='freq_1')
 
         edges = [(exp.chan1, avgr.sink),
                  (avgr.partial_average, printer_partial.sink),
@@ -144,8 +144,6 @@ class AverageTestCase(unittest.TestCase):
         exp.set_graph(edges)
 
         exp.add_sweep(exp.freq_1, np.linspace(0,9,10))
-        avgr.axis.value = 'freq_1'
-        avgr.update_descriptors()
         exp.run_sweeps()
 
 if __name__ == '__main__':
diff --git a/test/test_experiment.py b/test/test_experiment.py
index 64ba5297..6ec15025 100644
--- a/test/test_experiment.py
+++ b/test/test_experiment.py
@@ -138,7 +138,7 @@ class ExperimentTestCase(unittest.TestCase):
                  (pt.source, prnt.sink)]
 
         exp.set_graph(edges)
-
+        exp.update_descriptors()
         self.assertFalse(pt.sink.descriptor is None)
         self.assertFalse(prnt.sink.descriptor is None)
         self.assertTrue(exp.chan1.descriptor == pt.sink.descriptor)