/** * Adds this expression to the application package, such that it can be read later. * * @param name the name of this ranking expression - may have 1-3 parts separated by dot where the first part * is always the model name */ void writeExpression(String name, ExpressionFunction expression) { StringBuilder b = new StringBuilder(expression.getBody().getRoot().toString()); for (Map.Entry<String, TensorType> input : expression.argumentTypes().entrySet()) b.append('\n').append(input.getKey()).append('\t').append(input.getValue()); application.getFile(modelFiles.expressionPath(name)).writeFile(new StringReader(b.toString())); }
/** * Adds this constant to the application package as a file, * such that it can be distributed using file distribution. * * @return the path to the stored constant, relative to the application package root */ Path writeLargeConstant(String name, Tensor constant) { Path constantsPath = modelFiles.largeConstantsContentPath(); // "tbf" ending for "typed binary format" - recognized by the nodes receiving the file: Path constantPath = constantsPath.append(name + ".tbf"); // Remember the constant in a file we replicate in ZooKeeper application.getFile(modelFiles.largeConstantsInfoPath().append(name + ".constant")) .writeFile(new StringReader(name + ":" + constant.type() + ":" + correct(constantPath))); // Write content explicitly as a file on the file system as this is distributed using file distribution // - but only if this is a global model to avoid writing the same constants for each rank profile // where they are used if (modelFiles.modelName.isGlobal()) { createIfNeeded(constantsPath); IOUtils.writeFile(application.getFileReference(constantPath), TypedBinaryFormat.encode(constant)); } return correct(constantPath); }