Search in sources :

Example 11 with InvalidParameterException

use of com.tencent.angel.exception.InvalidParameterException in project angel by Tencent.

the class GetNeighbors method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    GeneralPartGetParam param = (GeneralPartGetParam) partParam;
    KeyPart keyPart = param.getIndicesPart();
    switch(keyPart.getKeyType()) {
        case LONG:
            {
                // Long type node id
                long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
                ServerLongAnyRow row = GraphMatrixUtils.getPSLongKeyRow(psContext, param);
                Long2ObjectOpenHashMap<long[]> nodeIdToNeighbors = new Long2ObjectOpenHashMap<>(nodeIds.length);
                for (long nodeId : nodeIds) {
                    if (row.get(nodeId) == null) {
                        // If node not exist, just skip
                        continue;
                    }
                    long[] neighbors = ((GraphNode) (row.get(nodeId))).getNeighbors();
                    if (neighbors != null) {
                        nodeIdToNeighbors.put(nodeId, neighbors);
                    }
                }
                return new PartGetNeighborsResult(param.getPartKey().getPartitionId(), nodeIdToNeighbors);
            }
        default:
            {
                // TODO: support String, Int, and Any type node id
                throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
            }
    }
}
Also used : InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) ServerLongAnyRow(com.tencent.angel.ps.storage.vector.ServerLongAnyRow)

Example 12 with InvalidParameterException

use of com.tencent.angel.exception.InvalidParameterException in project angel by Tencent.

the class GetLabels method partitionGet.

@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
    GeneralPartGetParam param = (GeneralPartGetParam) partParam;
    KeyPart keyPart = param.getIndicesPart();
    switch(keyPart.getKeyType()) {
        case LONG:
            {
                // Long type node id
                long[] nodeIds = ((ILongKeyPartOp) keyPart).getKeys();
                ServerLongFloatRow row = (ServerLongFloatRow) psContext.getMatrixStorageManager().getRow(param.getPartKey(), 0);
                LongArrayList keys = new LongArrayList();
                FloatArrayList vals = new FloatArrayList();
                for (int i = 0; i < nodeIds.length; i++) {
                    if (row.exist(nodeIds[i])) {
                        keys.add(nodeIds[i]);
                        vals.add(row.get(nodeIds[i]));
                    }
                }
                return new GetLabelsPartResult(keys.toLongArray(), vals.toFloatArray());
            }
        default:
            {
                // TODO: support String, Int, and Any type node id
                throw new InvalidParameterException("Unsupport index type " + keyPart.getKeyType());
            }
    }
}
Also used : InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) GeneralPartGetParam(com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam) LongArrayList(it.unimi.dsi.fastutil.longs.LongArrayList) ServerLongFloatRow(com.tencent.angel.ps.storage.vector.ServerLongFloatRow) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) FloatArrayList(it.unimi.dsi.fastutil.floats.FloatArrayList)

Example 13 with InvalidParameterException

use of com.tencent.angel.exception.InvalidParameterException in project angel by Tencent.

the class ModelContextUtils method createMatrixContext.

public static MatrixContext createMatrixContext(ModelContext context, String name, RowType rowType, Class<? extends IElement> elemClass, int rowNum) {
    if (rowType.isComplexValue() && elemClass == null) {
        throw new InvalidParameterException("Complex value type must set element class type");
    }
    MatrixContext mc = new MatrixContext();
    mc.setName(name);
    mc.setRowNum(rowNum);
    mc.setRowType(rowType);
    mc.setPartitionNum(context.getPartitionNum());
    mc.setValidIndexNum(context.getNodeNum());
    if (elemClass != null) {
        mc.setValueType(elemClass);
    }
    if (context.isUseHashPartition()) {
        mc.setPartitionerClass(HashPartitioner.class);
    } else {
        mc.setIndexStart(context.getMinNodeId());
        mc.setIndexEnd(context.getMaxNodeId());
        mc.setPartitionerClass(ColumnRangePartitioner.class);
        if (context.getPartitionNum() > 0) {
            mc.setMaxRowNumInBlock(1);
            mc.setMaxColNumInBlock((context.getMaxNodeId() - context.getMinNodeId()) / context.getPartitionNum());
        }
    }
    return mc;
}
Also used : InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) MatrixContext(com.tencent.angel.ml.matrix.MatrixContext)

Example 14 with InvalidParameterException

use of com.tencent.angel.exception.InvalidParameterException in project angel by Tencent.

the class ModelContextUtils method createMatrixContext.

public static MatrixContext createMatrixContext(ModelContext context, RowType rowType, Class<? extends IElement> elemClass, int rowNum) {
    if (rowType.isComplexValue() && elemClass == null) {
        throw new InvalidParameterException("Complex value type must set element class type");
    }
    MatrixContext mc = new MatrixContext();
    mc.setName(context.getModelName());
    mc.setRowNum(rowNum);
    mc.setRowType(rowType);
    mc.setPartitionNum(context.getPartitionNum());
    mc.setValidIndexNum(context.getNodeNum());
    if (elemClass != null) {
        mc.setValueType(elemClass);
    }
    if (context.isUseHashPartition()) {
        mc.setPartitionerClass(HashPartitioner.class);
    } else {
        mc.setIndexStart(context.getMinNodeId());
        mc.setIndexEnd(context.getMaxNodeId());
        mc.setPartitionerClass(ColumnRangePartitioner.class);
        if (context.getPartitionNum() > 0) {
            mc.setMaxRowNumInBlock(rowNum);
            mc.setMaxColNumInBlock((context.getMaxNodeId() - context.getMinNodeId()) / context.getPartitionNum());
        }
    }
    return mc;
}
Also used : InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) MatrixContext(com.tencent.angel.ml.matrix.MatrixContext)

Example 15 with InvalidParameterException

use of com.tencent.angel.exception.InvalidParameterException in project angel by Tencent.

the class MatrixClientFactory method get.

/**
 * Get a matrix client.
 *
 * @param matrixId matrix id
 * @param taskId   task id
 * @return MatrixClient matrix client
 * @throws InvalidParameterException matrix does not exist
 */
public static MatrixClient get(int matrixId, int taskId) throws InvalidParameterException {
    if (!PSAgentContext.get().getMatrixMetaManager().exist(matrixId)) {
        throw new InvalidParameterException("matrix with id " + matrixId + " does not exist.");
    }
    Key key = new Key(matrixId, taskId);
    MatrixClient client = cacheClients.get(key);
    if (client == null) {
        try {
            cacheClients.putIfAbsent(key, buildClient(matrixId, taskId, type));
        } catch (Exception x) {
            throw new InvalidParameterException("Invalid matrix client type:" + type.getClass().getName() + ", " + x.getMessage());
        }
        client = cacheClients.get(key);
    }
    return client;
}
Also used : InvalidParameterException(com.tencent.angel.exception.InvalidParameterException) InvalidParameterException(com.tencent.angel.exception.InvalidParameterException)

Aggregations

InvalidParameterException (com.tencent.angel.exception.InvalidParameterException)24 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)8 ServerLongAnyRow (com.tencent.angel.ps.storage.vector.ServerLongAnyRow)7 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)7 AngelException (com.tencent.angel.exception.AngelException)6 IOException (java.io.IOException)6 Path (org.apache.hadoop.fs.Path)4 MatrixMeta (com.tencent.angel.ml.matrix.MatrixMeta)3 GeneralPartGetParam (com.tencent.angel.ml.matrix.psf.get.base.GeneralPartGetParam)3 MatrixClient (com.tencent.angel.psagent.matrix.MatrixClient)3 PartGetFloatArrayAttrsResult (com.tencent.angel.graph.client.psf.get.utils.PartGetFloatArrayAttrsResult)2 PartGetIntArrayAttrsResult (com.tencent.angel.graph.client.psf.get.utils.PartGetIntArrayAttrsResult)2 IntFloatVector (com.tencent.angel.ml.math2.vector.IntFloatVector)2 LongFloatVector (com.tencent.angel.ml.math2.vector.LongFloatVector)2 MatrixContext (com.tencent.angel.ml.matrix.MatrixContext)2 ModelLineConvert (com.tencent.angel.tools.ModelLineConvert)2 TextModelLineConvert (com.tencent.angel.tools.TextModelLineConvert)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 Configuration (org.apache.hadoop.conf.Configuration)2