Пример #1
0
    def __init__(self, vp_value_count, output_shape, name='Full Network'):
        """
        Initializes the Full Network.
        :param output_shape: (5-tuple) The desired output shape for generated videos. Must match video input shape.
                              Legal values: (bsz, 3, 8, 112, 112) and (bsz, 3, 16, 112, 112)
        :param name: (str, optional) The name of the network (default 'Full Network').
        Raises:
            ValueError: if 'vp_value_count' is not a legal value count
            ValueError: if 'output_shape' does not contain a legal number of frames.
        """
        if vp_value_count not in self.VALID_VP_VALUE_COUNTS:
            raise ValueError('Invalid number of vp values: %d' % vp_value_count)
        if output_shape[2] not in self.VALID_FRAME_COUNTS:
            raise ValueError('Invalid number of frames in desired output: %d' % output_shape[2])

        super(FullNetwork, self).__init__()

        self.net_name = name
        self.vp_value_count = vp_value_count
        self.output_shape = output_shape
        self.out_frames = output_shape[2]

        self.vgg = vgg16(pretrained=True, weights_path=vgg_weights_path)
        self.i3d = InceptionI3d(final_endpoint='Mixed_5c_small', in_frames=self.out_frames,
                                pretrained=True, weights_path=i3d_weights_path)

        self.deconv = Deconv(in_channels=256, out_frames=self.out_frames)
        self.exp = Expander(vp_value_count=self.vp_value_count, out_frames=self.out_frames, out_size=28)
        self.trans = Transformer(in_channels=32 + self.vp_value_count)

        self.gen = Generator(in_channels=32 + 32, out_frames=self.out_frames)
Пример #2
0
 def testDoSubstitutionNoDefinition(self):
   if IGNORE_TEST:
     return
   executor = Executor()
   expander = Expander(executor, self.message)
   result = expander.do(SUBSTITUTION1)
   self.assertEqual(result[0], SUBSTITUTION1)
Пример #3
0
def session(file):
    print('\nWelcome to Vocabulary Expander!\n'
          '\nWhich mod do you prefer?\n'
          'Just write one of the given names:\n'
          'Smart / Simple\n'
          'To exit print 0.')

    mod = input()
    mod = mod.capitalize()

    while mod != 'Simple' and mod != 'Smart':
        if mod == '0':
            program_exit()
        print('Wrong value. Try again. To exit print 0.')
        mod = input()
        mod = mod.capitalize()

    expander = Expander(file, mod)

    print('\nWhat number of words would you like to learn for each iteration?'
          '\nTo exit print value 0 or less.')

    w_num = int(input())
    if w_num <= 0:
        program_exit()

    expander.teaching(w_num)
Пример #4
0
    def EnumerateExpanders(self):
        """Enumerate all storage expanders on the system

        returns:
            An array of object paths for storage expanders
        """
        l = list()
        for i in self.iface.EnumerateExpanders():
            obj = Expander(i)
            l.append(obj)
        return l
 def __init__(self, template_string):
     """
 :param str template_string: string containing template variables
     and template escape statements to execute
 """
     self._extractor = LineExtractor(template_string)
     self._message = StatusMessage(self._extractor)
     self._executor = Executor()
     self._expander = Expander(self._executor, self._message)
     self._command = None  # Command being processed
     self._define_variable_statements = []
Пример #6
0
 def testDo(self):
   if IGNORE_TEST:
     return
   executor = Executor()
   executor.setDefinitions(DEFINITIONS)
   expander = Expander(executor, self.message)
   result = expander.do(SUBSTITUTION1)
   self.assertEqual(result[0], SUBSTITUTION1)
   result = expander.do(SUBSTITUTION2)
   expected = len(DEFINITIONS['a'])
   self.assertEqual(len(result), expected)
Пример #7
0
 def testExpandTemplateExpressions(self):
   if IGNORE_TEST:
     return
   executor = Executor()
   var = 'n'
   definitions = {var: [1, 2, 3]}
   executor.setDefinitions(definitions)
   expander = Expander(executor, self.message)
   template = "T{%s} + A -> T{%s+1}" % (var, var)
   expansion = expander.do(template)
   self.assertEqual(len(expansion), len(definitions[var]))
   # Check that each substitution is found
   for value in definitions[var]:
     found = False
     for substitution in expansion:
       if "T%d" % value in substitution:
         found = True
         break
     self.assertTrue(found)
Пример #8
0
 def __init__(self):
     self.pattern = PATTERN
     self.sub_rule = GeochainsSubstitutionRule()
     self.geodb = GeoIPDBMaxMind()
     self.sub_rule.geodb = self.geodb
     self.expander = Expander(self.pattern, self.sub_rule)
Пример #9
0
    def createUi(self):
        self.content = Expander("Content", ":/images/parts.svg")
        self.images = Expander("Images", ":/images/images.svg")
        self.settings = Expander("Settings", ":/images/settings.svg")

        self.setWindowTitle(QCoreApplication.applicationName() + " " +
                            QCoreApplication.applicationVersion())
        vbox = QVBoxLayout()
        vbox.addWidget(self.content)
        vbox.addWidget(self.images)
        vbox.addWidget(self.settings)
        vbox.addStretch()

        self.content_list = QListWidget()
        self.content_list.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed)
        content_box = QVBoxLayout()
        content_box.addWidget(self.content_list)
        self.item_edit = QLineEdit()
        self.item_edit.setMaximumHeight(0)
        self.item_edit.editingFinished.connect(self.editItemFinished)
        self.item_anim = QPropertyAnimation(self.item_edit,
                                            "maximumHeight".encode("utf-8"))
        content_box.addWidget(self.item_edit)
        button_layout = QHBoxLayout()
        plus_button = FlatButton(":/images/plus.svg")
        self.edit_button = FlatButton(":/images/edit.svg")
        self.trash_button = FlatButton(":/images/trash.svg")
        self.up_button = FlatButton(":/images/up.svg")
        self.down_button = FlatButton(":/images/down.svg")
        self.trash_button.enabled = False
        self.up_button.enabled = False
        self.down_button.enabled = False
        button_layout.addWidget(plus_button)
        button_layout.addWidget(self.up_button)
        button_layout.addWidget(self.down_button)
        button_layout.addWidget(self.edit_button)
        button_layout.addWidget(self.trash_button)
        content_box.addLayout(button_layout)
        self.content.addLayout(content_box)
        plus_button.clicked.connect(self.addPart)
        self.trash_button.clicked.connect(self.dropPart)
        self.up_button.clicked.connect(self.partUp)
        self.down_button.clicked.connect(self.partDown)
        self.edit_button.clicked.connect(self.editPart)

        self.image_list = QListWidget()
        self.image_list.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed)
        image_box = QVBoxLayout()
        image_box.addWidget(self.image_list)
        image_button_layout = QHBoxLayout()
        image_plus_button = FlatButton(":/images/plus.svg")
        self.image_trash_button = FlatButton(":/images/trash.svg")
        self.image_trash_button.enabled = False
        image_button_layout.addWidget(image_plus_button)
        image_button_layout.addWidget(self.image_trash_button)
        image_box.addLayout(image_button_layout)
        self.images.addLayout(image_box)
        image_plus_button.clicked.connect(self.addImage)
        self.image_trash_button.clicked.connect(self.dropImage)

        scroll_content = QWidget()
        scroll_content.setLayout(vbox)
        scroll = QScrollArea()
        scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        scroll.setWidget(scroll_content)
        scroll.setWidgetResizable(True)
        scroll.setMaximumWidth(200)
        scroll.setMinimumWidth(200)

        self.navigationdock = QDockWidget("Navigation", self)
        self.navigationdock.setAllowedAreas(Qt.LeftDockWidgetArea
                                            | Qt.RightDockWidgetArea)
        self.navigationdock.setWidget(scroll)
        self.navigationdock.setObjectName("Navigation")
        self.addDockWidget(Qt.LeftDockWidgetArea, self.navigationdock)

        self.splitter = QSplitter()
        self.text_edit = MarkdownEdit()
        self.text_edit.setFont(QFont("Courier", 15))  # 11 on Linux
        self.preview = QWebEngineView()
        self.preview.setMinimumWidth(300)
        self.setWindowTitle(QCoreApplication.applicationName())

        self.splitter.addWidget(self.text_edit)
        self.splitter.addWidget(self.preview)
        self.setCentralWidget(self.splitter)

        self.content.expanded.connect(self.contentExpanded)
        self.images.expanded.connect(self.imagesExpanded)
        self.settings.expanded.connect(self.settingsExpanded)
        self.settings.clicked.connect(self.openSettings)
        self.content_list.currentItemChanged.connect(self.partSelectionChanged)
        self.image_list.currentItemChanged.connect(self.imageSelectionChanged)
        self.image_list.itemDoubleClicked.connect(self.insertImage)

        self.text_edit.undoAvailable.connect(self.undoAvailable)
        self.text_edit.redoAvailable.connect(self.redoAvailable)
        self.text_edit.copyAvailable.connect(self.copyAvailable)

        QApplication.clipboard().dataChanged.connect(self.clipboardDataChanged)
Пример #10
0
    def __init__(self):
        QMainWindow.__init__(self)
        self.setWindowTitle("Qt Expander Demo")
        self.resize(640, 480)

        edit = QTextEdit()
        edit.setPlainText("Lorem ipsum dolor...")
        self.content = Expander("Content", "parts.svg")
        self.images = Expander("Images", "images.svg")
        self.settings = Expander("Settings", "settings.svg")
        vbox = QVBoxLayout()
        vbox.addWidget(self.content)
        vbox.addWidget(self.images)
        vbox.addWidget(self.settings)
        vbox.addStretch()
        scroll_content = QWidget()
        scroll_content.setLayout(vbox)
        scroll = QScrollArea()
        scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        scroll.setWidget(scroll_content)
        scroll.setWidgetResizable(True)
        scroll.setMaximumWidth(200)
        scroll.setMinimumWidth(200)
        self.navigationdock = QDockWidget("Navigation", self)
        self.navigationdock.setAllowedAreas(Qt.LeftDockWidgetArea
                                            | Qt.RightDockWidgetArea)
        self.navigationdock.setWidget(scroll)
        self.navigationdock.setObjectName("Navigation")
        self.addDockWidget(Qt.LeftDockWidgetArea, self.navigationdock)
        self.setCentralWidget(edit)

        # fill content
        self.content_list = QListWidget()
        self.content_list.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed)
        for i in range(5):
            item = QListWidgetItem()
            item.setText("Item " + str(i))
            self.content_list.addItem(item)
        content_box = QVBoxLayout()
        content_box.addWidget(self.content_list)
        self.content.addLayout(content_box)

        # fill images
        self.images_list = QListWidget()
        self.images_list.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Fixed)
        for i in range(5):
            item = QListWidgetItem()
            item.setText("Image " + str(i))
            self.images_list.addItem(item)
        images_box = QVBoxLayout()
        images_box.addWidget(self.images_list)
        self.images.addLayout(images_box)

        #fill settings
        self.settings_list = QListWidget()
        self.settings_list.setSizePolicy(QSizePolicy.Ignored,
                                         QSizePolicy.Fixed)
        for i in range(5):
            item = QListWidgetItem()
            item.setText("Setting " + str(i))
            self.settings_list.addItem(item)
        settings_box = QVBoxLayout()
        settings_box.addWidget(self.settings_list)
        self.settings.addLayout(settings_box)

        self.content.expanded.connect(self.contentExpanded)
        self.images.expanded.connect(self.imagesExpanded)
        self.settings.expanded.connect(self.settingsExpanded)
Пример #11
0
 def __init__(self, id, parent):
     Widget.__init__(self, id, parent)
     self.widgets.expander = Expander()
     self.widgets.surface_table = FitTable()
     self.widgets.signal_table = FitTable()
Пример #12
0
 def setUp(self):
   self.extractor = LineExtractor("")
   self.message = StatusMessage(self.extractor)
   self.expander = Expander(Executor(), self.message)
Пример #13
0
def create_model():
    m = pe.ConcreteModel()
    m.fs = fs = FlowsheetBlock(default={"dynamic": False})
    fs.vapor_props = vapor_props = PhysicalParameterBlock(
        default={"valid_phase": 'Vap'})
    fs.properties = props = PhysicalParameterBlock(
        default={"valid_phase": ('Vap', 'Liq')})
    fs.reaction_params = MethanolReactionParameterBlock(
        default={'property_package': vapor_props})

    fs.feed = feed = Feed(default={"property_package": vapor_props})
    fs.compressor1 = IdealGasIsentropicCompressor(
        default={
            "property_package": vapor_props,
            "has_phase_equilibrium": False
        })
    fs.cooler1 = Heater(default={
        "property_package": vapor_props,
        "has_phase_equilibrium": False
    })
    fs.compressor2 = IdealGasIsentropicCompressor(
        default={
            "property_package": vapor_props,
            "has_phase_equilibrium": False
        })
    fs.equal_electric = pe.Constraint(
        expr=fs.compressor1.work[0.0] == fs.compressor2.work[0.0])
    fs.mixer = Mixer(
        default={
            'property_package': vapor_props,
            'inlet_list': ['feed', 'recycle'],
            'momentum_mixing_type': MomentumMixingType.equality
        })

    # Reactor
    fs.reactor = StoichiometricReactor(
        default={
            'property_package': vapor_props,
            'reaction_package': fs.reaction_params,
            'has_heat_of_reaction': True,
            'has_pressure_change': False
        })
    fs.reactor.conversion_eq = pe.Var()
    fs.reactor.t_inv = pe.Var()
    fs.reactor.p_sq_inv = pe.Var()
    fs.reactor.conversion = pe.Var()
    fs.reactor.consumption_rate = pe.Var()
    fs.reactor.t_inv_con = pe.Constraint(expr=fs.reactor.t_inv *
                                         fs.reactor.outlet.temperature[0] == 1)
    fs.reactor.p_sq_inv_con = pe.Constraint(
        expr=fs.reactor.p_sq_inv * fs.reactor.inlet.pressure[0]**2 == 1)
    fs.reactor.conversion_eq_con = pe.Constraint(expr=(
        fs.reactor.conversion_eq == 0.415 *
        (1 - 26.25 * pe.exp(-18 * fs.reactor.t_inv) * fs.reactor.p_sq_inv)))
    fs.reactor.conversion_con = pe.Constraint(
        expr=(fs.reactor.conversion == fs.reactor.conversion_eq *
              (1 - pe.exp(-5)) * (fs.reactor.inlet.mole_frac[0, "H2"] +
                                  fs.reactor.inlet.mole_frac[0, "CO"] +
                                  fs.reactor.inlet.mole_frac[0, "CH3OH"])))
    fs.reactor.consumption_rate_con = pe.Constraint(
        expr=(fs.reactor.consumption_rate == fs.reactor.conversion *
              fs.reactor.inlet.mole_frac[0, "H2"] *
              fs.reactor.inlet.flow_mol[0]))
    fs.reactor.h2_consumption_con = pe.Constraint(expr=(
        fs.reactor.outlet.flow_mol[0] *
        fs.reactor.outlet.mole_frac[0, "H2"] == fs.reactor.inlet.flow_mol[0] *
        fs.reactor.inlet.mole_frac[0, "H2"] - fs.reactor.consumption_rate))

    fs.expander = Expander(default={
        'property_package': vapor_props,
        'has_phase_equilibrium': False
    })
    fs.cooler2 = Heater(default={
        "property_package": vapor_props,
        "has_phase_equilibrium": False
    })
    fs.flash = Flash(default={"property_package": props})
    fs.purge_splitter = Separator(
        default={
            'property_package': vapor_props,
            'outlet_list': ['purge', 'recycle'],
            'ideal_separation': False
        })
    fs.compressor3 = IdealGasIsentropicCompressor(
        default={
            "property_package": vapor_props,
            "has_phase_equilibrium": False
        })

    ###########################
    # Set scaling factors
    ###########################
    fs.compressor1.control_volume.scaling_factor_energy.value = 1
    fs.compressor2.control_volume.scaling_factor_energy.value = 1
    fs.cooler1.control_volume.scaling_factor_energy.value = 1
    fs.flash.control_volume.scaling_factor_energy.value = 1
    fs.reactor.control_volume.scaling_factor_energy.value = 1
    fs.cooler2.control_volume.scaling_factor_energy.value = 1
    fs.compressor3.control_volume.scaling_factor_energy.value = 1
    fs.mixer.scaling_factor_energy.value = 1

    fs.cooler1.control_volume.scaling_factor_pressure.value = 1
    fs.flash.control_volume.scaling_factor_pressure.value = 1
    fs.reactor.control_volume.scaling_factor_pressure.value = 1
    fs.cooler2.control_volume.scaling_factor_pressure.value = 1

    ###########################
    # Objective
    ###########################
    m.objective = pe.Objective(expr=(-fs.flash.liq_outlet.flow_mol[0.0]))

    ###########################
    # Connect Units
    ###########################
    fs.stream1 = network.Arc(source=feed.outlet,
                             destination=fs.compressor1.inlet)
    fs.stream2 = network.Arc(source=fs.compressor1.outlet,
                             destination=fs.cooler1.inlet)
    fs.stream3 = network.Arc(source=fs.cooler1.outlet,
                             destination=fs.compressor2.inlet)
    fs.stream4 = network.Arc(source=fs.compressor2.outlet,
                             destination=fs.mixer.feed)
    fs.stream5 = network.Arc(source=fs.mixer.outlet,
                             destination=fs.reactor.inlet)
    fs.stream6 = network.Arc(source=fs.reactor.outlet,
                             destination=fs.expander.inlet)
    fs.stream7 = network.Arc(source=fs.expander.outlet,
                             destination=fs.cooler2.inlet)
    fs.stream8 = network.Arc(source=fs.cooler2.outlet,
                             destination=fs.flash.inlet)
    fs.stream9 = network.Arc(source=fs.flash.vap_outlet,
                             destination=fs.purge_splitter.inlet)
    fs.stream10 = network.Arc(source=fs.purge_splitter.recycle,
                              destination=fs.compressor3.inlet)
    fs.stream11 = network.Arc(source=fs.compressor3.outlet,
                              destination=fs.mixer.recycle)
    pe.TransformationFactory("network.expand_arcs").apply_to(m)

    ###########################
    # Set problem specs
    ###########################
    feed.flow_mol.fix(3.40898)
    feed.pressure.fix(1)
    feed.temperature.fix(3)
    feed.mole_frac[0.0, "CH4"].fix(0.05)
    feed.mole_frac[0.0, "CO"].fix(0.3)
    feed.mole_frac[0.0, "H2"].fix(0.6)
    feed.mole_frac[0.0, "CH3OH"].fix(0.05)

    fs.cooler1.heat_duty[0.0].setub(0)  # it is a cooler
    fs.cooler1.outlet.temperature[0.0].setlb(3)

    fs.flash.heat_duty.fix(0)
    fs.flash.deltaP.fix(0)

    fs.cooler2.heat_duty[0.0].setub(0)  # it is a cooler
    fs.cooler2.outlet.temperature[0.0].setlb(3)

    fs.compressor2.outlet.pressure[0.0].setub(10)
    fs.flash.liq_outlet.mole_frac[0.0, 'CH3OH'].expr.setlb(0.9)

    fs.purge_splitter.split_fraction[0.0, 'purge'].fix(0.05)

    ###########################
    # Prepare for initialization
    ###########################
    fs.compressor1.outlet.pressure.fix(5)
    fs.compressor2.outlet.pressure.fix(10)
    fs.cooler1.outlet.temperature.fix(3)
    fs.expander.outlet.pressure[0.0].fix(5)
    fs.cooler2.outlet.temperature[0.0].fix(3)
    fs.flash.liq_outlet.mole_frac[0.0, 'CH3OH'].expr.setlb(None)

    # Setup decomposition process
    seq = network.SequentialDecomposition()
    seq.options.select_tear_method = "heuristic"
    seq.options.tear_method = "Wegstein"
    seq.options.iterLim = 5

    # Determine tear stream and calculation order
    G = seq.create_graph(m)
    heu_result = seq.tear_set_arcs(G, method="heuristic")
    order = seq.calculation_order(G)

    # Display tear stream and calculation order
    print("Tear")
    for o in heu_result:
        print(o.name)
    print("Order")
    for o in order:
        for oo in o:
            print(oo.name)

    # Set guesses for tear stream
    tear_guesses = {
        "flow_mol": {
            0: 10
        },
        "mole_frac": {
            (0, 'CH3OH'): 0.06,
            (0, 'CH4'): 0.21,
            (0, 'CO'): 0.24,
            (0, 'H2'): 0.50
        },
        "temperature": {
            0: 4.4
        },
        "pressure": {
            0: 15
        }
    }
    seq.set_guesses_for(m.fs.reactor.inlet, tear_guesses)

    # Define method for initialising each block
    def function(unit):
        unit.initialize(outlvl=1)

    # Run sequential initialisation
    seq.run(m, function)

    ###########################
    # Unfix vars that were fixed for initialization
    ###########################
    m.fs.compressor1.outlet.pressure.unfix()
    m.fs.compressor2.outlet.pressure.unfix()
    m.fs.cooler1.outlet.temperature.unfix()
    m.fs.expander.outlet.pressure.unfix()
    m.fs.cooler2.outlet.temperature.unfix()
    m.fs.flash.liq_outlet.mole_frac[0.0, 'CH3OH'].expr.setlb(0.9)

    return m