Skip to content

Commit

Permalink
Added criterion reference support. Fixes #369 (#450)
Browse files Browse the repository at this point in the history
WIP #369 Removed criterion filter

WIP #396 Added criterion layers to nn seed

WIP #369 Added GenerateCriterion plugin

WIP #369 Added GenerateCriterion to criterion meta

WIP #369 Filtered criterion from the ArchEditor

WIP Removed old css

WIP #369 filtered criterion types

WIP #369. Fixed criterion pointer assignment

WIP #369 Fixed criterion execution problems

WIP #369 Updated seeds

WIP #369 Fixed failing test
  • Loading branch information
brollb authored Jul 7, 2016
1 parent 14c0af8 commit b96f2a8
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 8,197 deletions.
3 changes: 1 addition & 2 deletions src/plugins/CreateTorchMeta/CreateTorchMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ define([
layers;

try {
layers = JSON.parse(text)
.filter(layer => layer.type !== 'Criterion');
layers = JSON.parse(text);
} catch (e) {
return callback('JSON parse error: ' + e, this.result);
}
Expand Down
69 changes: 69 additions & 0 deletions src/plugins/GenerateCriterion/GenerateCriterion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*globals define*/
/*jshint node:true, browser:true*/

define([
'text!./metadata.json',
'plugin/PluginBase'
], function (
pluginMetadata,
PluginBase
) {
'use strict';

pluginMetadata = JSON.parse(pluginMetadata);

/**
* Initializes a new instance of GenerateCriterion.
* @class
* @augments {PluginBase}
* @classdesc This class represents the plugin GenerateCriterion.
* @constructor
*/
var GenerateCriterion = function () {
// Call base class' constructor.
PluginBase.call(this);
this.pluginMetadata = pluginMetadata;
};

/**
* Metadata associated with the plugin. Contains id, name, version, description, icon, configStructue etc.
* This is also available at the instance at this.pluginMetadata.
* @type {object}
*/
GenerateCriterion.metadata = pluginMetadata;

// Prototypical inheritance from PluginBase.
GenerateCriterion.prototype = Object.create(PluginBase.prototype);
GenerateCriterion.prototype.constructor = GenerateCriterion;

/**
* Main function for the plugin to execute. This will perform the execution.
* Notes:
* - Always log with the provided logger.[error,warning,info,debug].
* - Do NOT put any user interaction logic UI, etc. inside this method.
* - callback always has to be called even if error happened.
*
* @param {function(string, plugin.PluginResult)} callback - the result callback
*/
GenerateCriterion.prototype.main = function (callback) {
// Generate the code for the criterion layer and return a file
var name = this.core.getAttribute(this.activeNode, 'name'),
code = `require 'nn'\nreturn nn.${name}()`,
filename = `${name}.lua`;

// Using the logger.
this.logger.debug(`Generating code for ${name} criterion layer.`);

// Save the file
this.blobClient.putFile(filename, code)
.then(hash => {
this.result.setSuccess(true);
this.result.addArtifact(hash);
callback(null, this.result);
})
.catch(err => callback(err, this.result));

};

return GenerateCriterion;
});
14 changes: 14 additions & 0 deletions src/plugins/GenerateCriterion/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "GenerateCriterion",
"name": "Generate Criterion Code",
"version": "0.1.0",
"description": "",
"icon": {
"class": "glyphicon glyphicon-cog",
"src": ""
},
"disableServerSideExecution": false,
"disableBrowserSideExecution": false,
"writeAccessRequired": false,
"configStructure": []
}
Binary file modified src/seeds/cifar10/cifar10.webgmex
Binary file not shown.
Binary file modified src/seeds/nn/nn.webgmex
Binary file not shown.
Binary file modified src/seeds/project/project.webgmex
Binary file not shown.
13 changes: 9 additions & 4 deletions src/visualizers/panels/ArchEditor/ArchEditorControl.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/*globals define */
/*jshint browser: true*/
/**
* Generated by VisualizerGenerator 1.7.0 from webgme on Tue May 17 2016 11:25:46 GMT-0400 (EDT).
*/

define([
'deepforge/globals',
Expand Down Expand Up @@ -91,6 +88,7 @@ define([
return desc;
};

////////////////////////// Layer Selection Logic //////////////////////////
ArchEditorControl.prototype._getValidInitialNodes = function() {
return this._client.getChildrenMeta(this._currentNodeId).items
// For now, anything is possible!
Expand All @@ -102,7 +100,14 @@ define([
return !this._client.getNode(nodeId).isAbstract();
})
.map(id => this._getObjectDescriptor(id))
.filter(obj => !obj.isConnection && obj.name !== 'Connection');
.filter(obj => !obj.isConnection && obj.name !== 'Connection')
.filter(layer => layer.layerType !== 'Criterion');
};

ArchEditorControl.prototype._getValidSuccessorNodes = function(id) {
return EasyDAGControl.prototype._getValidSuccessorNodes.call(this, id)
// Remove the Criterion layers
.filter(pair => pair.node.layerType !== 'Criterion');
};

// Widget extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ define([
var notTypes = ['Data', 'Operation', 'Pipeline'];
return this._client.getAllMetaNodes()
.filter(node => {
var plugins = node.getRegistry('validPlugins');
var plugins = node.getOwnRegistry('validPlugins');
// Convention is enforced; if the plugin generates lua artifacts,
// it should be called `Generate`.. (something)
return plugins && plugins.indexOf('Generate') !== -1;
Expand Down
27 changes: 27 additions & 0 deletions src/visualizers/panels/PipelineEditor/PipelineEditorControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,5 +617,32 @@ define([
}
};

////////////////////// Criterion Support //////////////////////
PipelineEditorControl.prototype._getValidTargetsFor = function (id, ptr) {
// Check if the pointer is a Criterion pointer -> if so, only show the meta types
// and the ones in the custom layer dir
var typeIds = this._client.getPointerMeta(id, ptr).items.map(item => item.id),
types = typeIds.map(id => this._client.getNode(id)),
criterion = types.find(node => node.getAttribute('name') === 'Criterion'),
items,
criterionId;

if (criterion) {
// Get all criterion types
criterionId = criterion.getId();
items = this._client.getAllMetaNodes().map(node => node.getId())
.filter(id => this._client.isTypeOf(id, criterionId));

return items.map(id => {
return {
node: this._getObjectDescriptor(id)
};
});
} else {
return EasyDAGControl.prototype._getValidTargetsFor.apply(this, arguments);
}

};

return PipelineEditorControl;
});
Loading

0 comments on commit b96f2a8

Please sign in to comment.