Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sigma.js demo using node-rapids #392

Merged
merged 79 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
a2508d0
index on fea-json-to-dataframe: 4daef83e npm pack then install llnode…
thomcom Apr 26, 2022
c604d85
WIP on fea-json-to-dataframe: 4daef83e npm pack then install llnode d…
thomcom Apr 26, 2022
3aeead0
Merge branch 'main' of github.com:rapidsai/node into fea-json-to-data…
trxcllnt May 2, 2022
9a5ce7e
Add split component of multibyte_split for better parsing.
thomcom May 2, 2022
f0e5c1a
Merge branch 'fea-json-to-dataframe' of github.com:thomcom/node into …
trxcllnt May 3, 2022
0fdeb9c
Added json_aos_to_dataframe.
thomcom May 4, 2022
e9b3173
Add the full test for loading the graphology dataset.
thomcom May 4, 2022
7cecc71
Passing test, needs a good fixture now though.
thomcom May 4, 2022
16163aa
Add less to dockerfile for git diff. Tweak the APIs slightly.
thomcom May 5, 2022
f2494ac
Commit various change requests.
thomcom May 5, 2022
2c98dec
Resolve Dockerfile conflict wrt less
thomcom May 5, 2022
0e5175c
Cleaning it up, and docs.
thomcom May 5, 2022
1bd7fa8
Move column tests to string tests.
thomcom May 5, 2022
628f221
Commit with sigma-server directory and rapids-api-server directories …
thomcom May 12, 2022
003c58d
Merge branch 'fea-json-to-dataframe' into fea-sigma-and-server
thomcom May 12, 2022
f6ccc10
Get it working with TypeScript.
thomcom May 12, 2022
a32a77e
Write fastify server that can read graphology datasets.
thomcom May 13, 2022
8c56868
First pass with fully working fastify server.
thomcom May 17, 2022
233606d
Trying to add fastify-arrow now
thomcom May 17, 2022
45d3ae1
Final batch of review changes.
thomcom May 17, 2022
ee1f012
Merge branch 'fea-json-to-dataframe' of github.com:thomcom/node into …
trxcllnt May 18, 2022
3133d46
Apply suggestions from code review
trxcllnt May 18, 2022
682915f
Merge branch 'fea-json-to-dataframe' of github.com:thomcom/node into …
trxcllnt May 18, 2022
e013dd0
move readText from StringSeries to Series
trxcllnt May 18, 2022
f681da8
update npmrc option
trxcllnt May 18, 2022
777266c
remove unused imports
trxcllnt May 18, 2022
1558df5
compare split values
trxcllnt May 18, 2022
6e79e37
Merge branch 'fea-json-to-dataframe' into fea-sigma-and-server
thomcom May 18, 2022
921b21a
Get Arrow Table streaming working from server.
thomcom May 19, 2022
ca6db64
Add sigma-server to lerna.
thomcom May 19, 2022
9c17d37
Merge remote-tracking branch 'upstream/main' into fea-sigma-and-server
thomcom May 20, 2022
f763d31
rapids-api-server working with sigma.js example demo.
thomcom May 23, 2022
ea7100d
Now feeding tables for demo data for sigma.js
thomcom May 25, 2022
5883cf2
Tile data for rendering.
thomcom May 27, 2022
ffbb652
Now feed edges to Sigma.
thomcom May 27, 2022
545be5f
Edges rendering.
thomcom May 27, 2022
cd8e95e
Remove yarn.lock
thomcom May 31, 2022
6c1b470
Clean up a typo and improve package.json for rapids-api-server.
thomcom Jun 3, 2022
ab49025
Remove tsconfig because there's no TypeScript in here?
thomcom Jun 3, 2022
fe42b31
Update modules/demo/rapids-api-server/routes/graphology/index.js
thomcom Jun 3, 2022
bfe62a0
Update modules/demo/rapids-api-server/routes/graphology/index.js
thomcom Jun 3, 2022
e1ea36e
Update modules/demo/rapids-api-server/routes/graphology/index.js
thomcom Jun 3, 2022
55004f5
Merge remote-tracking branch 'upstream/main' into fea-sigma-and-server
thomcom Jun 3, 2022
80af506
Update modules/demo/rapids-api-server/routes/graphology/index.js
thomcom Jun 3, 2022
0ff89cc
Update fastify-arrow to 1.0.0
thomcom Jun 3, 2022
fb81696
Remove a few unneeded files and fix root package.json
thomcom Jun 3, 2022
9ebc1da
Don't want a sigma.js submodule atm.
thomcom Jun 6, 2022
b5e98d1
Cleaning up to support Arrow.
thomcom Jun 6, 2022
b7caea0
Force typescript to 4.6.4 for now, due to an autoformatting problem t…
thomcom Jun 7, 2022
aaa4632
Fix routing for apache arrow in two demo modules and fixes for rapids…
thomcom Jun 8, 2022
352b13c
Fixing up API server by adding tests!
thomcom Jun 13, 2022
4b5bbbd
Wrote most of the tests. Stuck on one that is appearing a hang, but I…
thomcom Jun 15, 2022
6feff02
Endless runaround from node tap
thomcom Jun 15, 2022
ba2e459
Endless runaround from node tap
thomcom Jun 15, 2022
3dd5c68
Tests almost working. Add some semicolons.
thomcom Jun 16, 2022
aa6342d
They all work. Hard won.
thomcom Jun 16, 2022
535af17
Create and pass another test.
thomcom Jun 16, 2022
22d0fd7
Add proper file loading for large_graph_demo
thomcom Jun 17, 2022
0076285
Adding arrow based GET tests.
thomcom Jun 17, 2022
1bf63aa
Pass all tests.
thomcom Jun 17, 2022
6e29681
Pass all tests with proper data expectations.
thomcom Jun 17, 2022
83fc63b
Rename to api-server and create a detailed README.md
thomcom Jun 17, 2022
8710adc
Update naming and improve package.json, make index.js executable.
thomcom Jun 21, 2022
6514049
One more package change maybe.
thomcom Jun 21, 2022
7f6f874
Fix typescript issue lingering.
thomcom Jun 21, 2022
403cb6a
Missing end tag for last block in README.md
thomcom Jun 21, 2022
9a605c0
Make root and graphology schemas match.
thomcom Jun 22, 2022
7c5aaab
Fix gpu_cache tests and add copyrights.
thomcom Jun 22, 2022
d2189eb
Refactor math a little, remove unneeded typescript override.
thomcom Jun 22, 2022
b1df583
Type hints.
thomcom Jun 22, 2022
7ca254b
Merge
thomcom Jun 22, 2022
50a63f2
Crucial small changes to fix syncronization with sigma.js/examples/ex…
thomcom Jun 23, 2022
1ba06f9
Get rid of various uses of ._col and get better error checking in tests.
thomcom Jun 24, 2022
5496fee
Found one more ._col
thomcom Jun 24, 2022
200255e
Autocomplete gives me a weird import.
thomcom Jun 24, 2022
3182da0
Update modules/demo/api-server/util/gpu_cache.js
thomcom Jun 24, 2022
8bdc645
Update modules/demo/api-server/util/gpu_cache.js
thomcom Jun 24, 2022
4b42296
Update modules/demo/api-server/routes/graphology/index.js
thomcom Jun 24, 2022
a259809
Update modules/demo/api-server/util/gpu_cache.js
thomcom Jun 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"modules/demo/ssr/*",
"modules/demo/tfjs/*",
"modules/demo/client-server",
"modules/demo/api-server",
"modules/demo/viz-app",
"modules/demo/sql/*"
]
Expand Down
2 changes: 1 addition & 1 deletion modules/cudf/src/column/from_arrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class DataToColumnVisitor extends arrow.Visitor {
}
visitStruct<T extends arrow.Struct>(data: arrow.Data<T>) {
const {type, length, nullBitmap: nullMask} = data;
const children = type.children.map((_, i) => this.visit(data.children[i] ));
const children = type.children.map((_, i) => this.visit(data.children[i]));
return new Column({
length,
type: new Struct(children.map(
Expand Down
2 changes: 1 addition & 1 deletion modules/cudf/src/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ export class AbstractSeries<T extends DataType = any> {
* Copy the underlying device memory to host, and return an Iterator of the values.
*/
[Symbol.iterator](): IterableIterator<T['TValue']|null> {
return this.toArrow()[Symbol.iterator]() ;
return this.toArrow()[Symbol.iterator]();
}

/**
Expand Down
10 changes: 5 additions & 5 deletions modules/cudf/test/series/list-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('ListSeries', () => {

test('Can create from Arrow', () => {
const vec = listsOfInt32s([[0, 1, 2], [3, 4, 5]]);
const ints = vec.getChildAt<arrow.Int32>(0)! ;
const ints = vec.getChildAt<arrow.Int32>(0)!;
const col = Series.new(vec);

validateOffsets(vec, col);
Expand Down Expand Up @@ -75,8 +75,8 @@ describe('ListSeries', () => {

test('Can create a List of Lists from Arrow', () => {
const vec = listsOfListsOfInt32s([[[0, 1, 2]], [[3, 4, 5], [7, 8, 9]]]);
const list = vec.getChildAt<ListOfInt32>(0)! ;
const ints = list.getChildAt<arrow.Int32>(0)! ;
const list = vec.getChildAt<ListOfInt32>(0)!;
const ints = list.getChildAt<arrow.Int32>(0)!;
const col = Series.new(vec);

validateOffsets(vec, col);
Expand All @@ -86,8 +86,8 @@ describe('ListSeries', () => {

test('Can gather a List of Lists', () => {
const vec = listsOfListsOfInt32s([[[0, 1, 2]], [[3, 4, 5], [7, 8, 9]]]);
const list = vec.getChildAt<ListOfInt32>(0)! ;
const ints = list.getChildAt<arrow.Int32>(0)! ;
const list = vec.getChildAt<ListOfInt32>(0)!;
const ints = list.getChildAt<arrow.Int32>(0)!;
const col = Series.new(vec);
const out = col.gather(Series.new({type: new Int32, data: new Int32Array([0, 1, 2])}));

Expand Down
16 changes: 8 additions & 8 deletions modules/cudf/test/series/struct-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('StructSeries', () => {
{x: 1, y: 4},
{x: 2, y: 5},
]);
const xs = vec.getChildAt<arrow.Int32>(0)! ;
const ys = vec.getChildAt<arrow.Int32>(1)! ;
const xs = vec.getChildAt<arrow.Int32>(0)!;
const ys = vec.getChildAt<arrow.Int32>(1)!;

const col = Series.new(vec);

Expand All @@ -53,9 +53,9 @@ describe('StructSeries', () => {
{point: {x: 1, y: 4}},
{point: {x: 2, y: 5}},
]);
const points = vec.getChildAt<StructOfInt32>(0)! ;
const xs = points.getChildAt<arrow.Int32>(0)! ;
const ys = points.getChildAt<arrow.Int32>(1)! ;
const points = vec.getChildAt<StructOfInt32>(0)!;
const xs = points.getChildAt<arrow.Int32>(0)!;
const ys = points.getChildAt<arrow.Int32>(1)!;
const col = Series.new(vec);

validateElements(xs, col.getChild('point').getChild('x'));
Expand All @@ -74,9 +74,9 @@ describe('StructSeries', () => {
expect(out.type.children[0].type.children[0].name).toEqual('x');
expect(out.type.children[0].type.children[1].name).toEqual('y');

const points = vec.getChildAt<StructOfInt32>(0)! ;
const xs = points.getChildAt<arrow.Int32>(0)! ;
const ys = points.getChildAt<arrow.Int32>(1)! ;
const points = vec.getChildAt<StructOfInt32>(0)!;
const xs = points.getChildAt<arrow.Int32>(0)!;
const ys = points.getChildAt<arrow.Int32>(1)!;

validateElements(xs, col.getChild('point').getChild('x'));
validateElements(ys, col.getChild('point').getChild('y'));
Expand Down
42 changes: 34 additions & 8 deletions modules/demo/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,27 @@
}
],
"configurations": [
{
"name": "Attach Test",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"type": "node",
"request": "launch",
"name": "Debug Demo (TS only)",
"program": "${workspaceFolder}/${input:DEMO_NAME}",
"stopOnEntry": false,
"args": ["${input:DEMO_ARGS}"],
"runtimeArgs": ["--experimental-vm-modules"],
"args": [
"${input:DEMO_ARGS}"
],
"runtimeArgs": [
"--experimental-vm-modules"
],
"cwd": "${workspaceFolder}/${input:DEMO_NAME}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
Expand All @@ -44,7 +57,9 @@
{
"name": "Debug Demo (launch gdb)",
// hide the individual configurations from the debug dropdown list
"presentation": { "hidden": true },
"presentation": {
"hidden": true
},
"type": "cppdbg",
"request": "launch",
"stopAtEntry": false,
Expand All @@ -62,9 +77,18 @@
],
"program": "${input:NODE_BINARY}",
"environment": [
{ "name": "NODE_DEBUG", "value": "1" },
{ "name": "NODE_NO_WARNINGS", "value": "1" },
{ "name": "NODE_ENV", "value": "production" },
{
"name": "NODE_DEBUG",
"value": "1"
},
{
"name": "NODE_NO_WARNINGS",
"value": "1"
},
{
"name": "NODE_ENV",
"value": "production"
},
// { "name": "READABLE_STREAM", "value": "disable" },
],
"args": [
Expand All @@ -80,7 +104,9 @@
"type": "node",
"request": "attach",
// hide the individual configurations from the debug dropdown list
"presentation": { "hidden": true },
"presentation": {
"hidden": true
},
"port": 9229,
"timeout": 60000,
"cwd": "${workspaceFolder}",
Expand Down Expand Up @@ -113,7 +139,7 @@
"command": "shellCommand.execute",
"args": {
"description": "Select a demo to debug",
"command": "echo client-server viz-app luma graph spatial xterm $(find modules/demo/deck modules/demo/tfjs modules/demo/ipc modules/demo/ssr modules/demo/sql -maxdepth 2 -type f -name 'package.json' -print0 | grep -z -v node_modules | tr -d '\\0' | sed -r 's@modules/demo/@@g' | sed -r 's@/package.json@ @g') | sort -Vr | sed -r 's@\\s@\\n@g'",
"command": "echo client-server viz-app api-server luma graph spatial xterm $(find modules/demo/deck modules/demo/tfjs modules/demo/ipc modules/demo/ssr modules/demo/sql -maxdepth 2 -type f -name 'package.json' -print0 | grep -z -v node_modules | tr -d '\\0' | sed -r 's@modules/demo/@@g' | sed -r 's@/package.json@ @g') | sort -Vr | sed -r 's@\\s@\\n@g'",
}
},
]
Expand Down
58 changes: 58 additions & 0 deletions modules/demo/api-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# 0x
profile-*

# mac files
.DS_Store

# vim swap files
*.swp

# webstorm
.idea

# vscode
.vscode
*code-workspace

# clinic
profile*
*clinic*
*flamegraph*
87 changes: 87 additions & 0 deletions modules/demo/api-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Fastify HTTP Server Demo

This project is a Fastify-based node http server that allows
commands and data to be sent to and from the NVIDIA GPUs installed
on the host machine.

Essentially, the node-rapids system is provided as a backend to any
HTTP client. At this time only limited functionality is available to
load JSON files in the `graphology` graph dataset format, plus API
requests to request Dataframes and their Columns via `apache-arrow`.

Two endpoints, `graphology/nodes` and `graphology/edges` specifically
return pre-formatted arrays that can be used directly with the
[sigma.js](https://github.com/jacomyal/sigma.js) renderer. An
[extra-large-graphs](https://github.com/jacomyal/sigma.js/pull/1252) example PR is in the works
that utilizes this GPU-accelerated data for rendering larger datasets
than available via only CPU.

## Main Dependencies
- @rapidsai/cudf
- fastify
- fastify-arrow
- apache-arrow

An example project that demonstrates this API has a PR being reviewed at [sigma.js](https://github.com/jacomyal/sigma.js),
but this project does not depend on sigma.js.j

## Installation

To install dependencies, run the following from the root directory for `node-rapids`

```bash
yarn
```

To run the demo
```bash
# Select the api-server demo from the list of demos
yarn demo
# OR specifically with
cd modules/demo/api-server
yarn start
```

## Dataset

Run the graph generator at https://github.com/thomcom/sigma.js/blob/add-gpu-graph-to-example/examples/extra-large-graphs/generate-graph.js
to create a very large graph using the object

```js
const state = {
order: 1000000,
size: 2000000,
clusters: 3,
edgesRenderer: 'edges-fast'
};
```

You don't need to edit the file in order to create a graph of the above size. Simply call the .js via node:

```bash
node graph-generator.js
```

Which will create a file `./large-graph.json`. Copy `./large-graph.json` into `api-server/` and then set your
API request to the location of the file relative to `routes/graphology/index.js`:

```
curl http://localhost:3000/graphology/read_large_demo?filename=../../large-graph.json
```

Which will use parallel JSON parsing to load the graph onto the GPU.

## Routes

```txt
/
/graphology
/graphology/read_json
/graphology/read_large_demo
/graphology/list_tables
/graphology/get_table/:table
/graphology/get_column/:table/:column
/graphology/nodes/bounds
/graphology/nodes
/graphology/edges
/graphology/release
22 changes: 22 additions & 0 deletions modules/demo/api-server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const path = require('path')
const AutoLoad = require('@fastify/autoload')

module.exports = async function(fastify, opts) {
// Place here your custom code!

// Do not touch the following lines

// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
fastify.register(AutoLoad,
{dir: path.join(__dirname, 'plugins'), options: Object.assign({}, opts)})

// This loads all plugins defined in routes
// define your routes in one of these
fastify.register(
AutoLoad,
{dir: path.join(__dirname, 'routes'), options: Object.assign({}, opts), ignorePattern: /.*.ts/})
}
33 changes: 33 additions & 0 deletions modules/demo/api-server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env node

// Copyright (c) 2022, NVIDIA CORPORATION.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

const Path = require('path');

// Change cwd to the example dir so relative file paths are resolved
process.chdir(__dirname);

const fastify = require.resolve('fastify-cli/cli.js');

const {spawnSync} = require('child_process');

const env = {
NEXT_TELEMETRY_DISABLED: 1, // disable https://fastifyjs.org/telemetry
...process.env,
};

spawnSync(process.execPath,
[fastify, 'start', '-l', 'info', '-P', '-w', 'app.js'],
{env, cwd: __dirname, stdio: 'inherit'});
Loading