Skip to content

Commit

Permalink
*/pkg.json: add watch cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
tharvik committed Feb 12, 2024
1 parent 8a06149 commit a42b435
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 378 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/lint-test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
working-directory: ./

lint-lib-core:
needs: build-lib-node
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -37,6 +38,7 @@ jobs:
node-version: ${{ env.node_version }}
cache: npm
- run: npm ci
- run: npm run build --workspace=@epfml/discojs-{core,node}
- run: npm run lint

lint-lib-node:
Expand Down Expand Up @@ -302,7 +304,7 @@ jobs:
- uses: cypress-io/github-action@v4
with:
browser: chromium
start: npm run dev
start: npm start
wait-on: http://localhost:8080/
working-directory: ${{ env.client_dir }}
config: baseUrl=http://localhost:8080/#/
Expand Down
2 changes: 2 additions & 0 deletions cli/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# built
/dist/
7 changes: 5 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"private": true,
"main": "dist/benchmark.ts",
"scripts": {
"watch": "nodemon --ext ts --ignore dist --watch ../discojs/discojs-node/dist --watch ../server/dist --exec npm run",
"start": "npm run build && node dist/benchmark.js",
"build": "tsc",
"test": ": nothing",
"start": "npm run build && node dist/benchmark.js"
"lint": "npx eslint --max-warnings 0 .",
"test": ": nothing"
},
"author": "",
"license": "ISC",
Expand All @@ -23,6 +25,7 @@
"eslint-plugin-import": "2",
"eslint-plugin-node": "11",
"eslint-plugin-promise": "5",
"nodemon": "3",
"ts-command-line-args": "2"
}
}
2 changes: 1 addition & 1 deletion cli/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src"]
"exclude": []
}
3 changes: 2 additions & 1 deletion cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"baseUrl": "src",
"outDir": "dist",
},
"include": ["src"]
"include": ["src"],
"exclude": ["**/*.spec.ts"]
}
4 changes: 3 additions & 1 deletion discojs/discojs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"watch": "nodemon --ext ts --ignore dist --exec npm run",
"build": "tsc",
"lint": "npx eslint --max-warnings 0 .",
"test": "mocha",
"lint": "npx eslint --max-warnings 0 --ignore-pattern '*.spec.ts' .",
"docs": "typedoc ./src/index.ts --theme oxide"
},
"repository": {
Expand Down Expand Up @@ -41,6 +42,7 @@
"eslint": "7",
"eslint-config-standard-with-typescript": "21",
"mocha": "9",
"nodemon": "3",
"ts-node": "10",
"typedoc": "0.22",
"typedoc-theme-oxide": "0.1",
Expand Down
26 changes: 14 additions & 12 deletions discojs/discojs-core/src/validation/validator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { assert } from 'chai'
import fs from 'fs'

import { Task, node, Validator, ConsoleLogger, EmptyMemory,
client as clients, data, aggregator, defaultTasks } from '@epfml/discojs-node'
import {
Task, node, Validator, ConsoleLogger, EmptyMemory,
client as clients, data, aggregator, defaultTasks
} from '@epfml/discojs-node'

const simplefaceMock = {
taskID: 'simple_face',
Expand Down Expand Up @@ -62,23 +64,23 @@ describe('validator', () => {
const titanicTask = defaultTasks.titanic.getTask()
const files = ['../../example_training_data/titanic_train.csv']
const data: data.Data = (await new node.data.NodeTabularLoader(titanicTask, ',').loadAll(files, {
features: titanicTask.trainingInformation.inputColumns,
labels: titanicTask.trainingInformation.outputColumns,
shuffle: false
})).train
features: titanicTask.trainingInformation.inputColumns,
labels: titanicTask.trainingInformation.outputColumns,
shuffle: false
})).train
const buffer = new aggregator.MeanAggregator(titanicTask)
const client = new clients.Local(new URL('http://localhost:8080'), titanicTask, buffer)
buffer.setModel(await client.getLatestModel())
const validator = new Validator(titanicTask,
new ConsoleLogger(),
new EmptyMemory(),
undefined,
client)
const validator = new Validator(titanicTask,
new ConsoleLogger(),
new EmptyMemory(),
undefined,
client)
await validator.assess(data)
// data.size is undefined because tfjs handles dataset lazily
// instead we count the dataset size manually
let size = 0
await data.dataset.forEachAsync(() => size+=1)
await data.dataset.forEachAsync(() => { size += 1 })
assert(
validator.visitedSamples === size,
`expected ${size} visited samples but got ${validator.visitedSamples}`
Expand Down
4 changes: 2 additions & 2 deletions discojs/discojs-core/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../tsconfig.base.json",
"include": ["src"],
"extends": "./tsconfig.json",
"exclude": []
}
8 changes: 5 additions & 3 deletions discojs/discojs-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"watch": "nodemon --ext ts --ignore dist --watch ../discojs-core/dist --exec npm run",
"build": "tsc",
"lint": "npx eslint --max-warnings 0 .",
"test": "mocha",
"lint": "npx eslint --max-warnings 0 --ignore-pattern '*.spec.ts' .",
"docs": "typedoc ./src/imports.ts --theme oxide"
},
"repository": {
Expand All @@ -19,9 +20,10 @@
"homepage": "https://github.com/epfml/disco#readme",
"dependencies": {
"@epfml/discojs-core": "*",
"@tensorflow/tfjs-node": "^4.17.0"
"@tensorflow/tfjs-node": "4"
},
"devDependencies": {
"@types/node": "20"
"@types/node": "20",
"nodemon": "3"
}
}
2 changes: 1 addition & 1 deletion discojs/discojs-node/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": []
}
6 changes: 5 additions & 1 deletion discojs/discojs-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"watch": "nodemon --ext ts --ignore dist --watch ../discojs-core/dist --exec npm run",
"build": "tsc",
"lint": "npx eslint --max-warnings 0 .",
"test": ": nothing",
"lint": "npx eslint --max-warnings 0 --ignore-pattern '*.spec.ts' .",
"docs": "typedoc ./src/index.ts --theme oxide"
},
"repository": {
Expand All @@ -19,5 +20,8 @@
"homepage": "https://github.com/epfml/disco#readme",
"dependencies": {
"@epfml/discojs-core": "*"
},
"devDependencies": {
"nodemon": "3"
}
}
2 changes: 1 addition & 1 deletion discojs/discojs-web/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": []
}
1 change: 1 addition & 0 deletions discojs/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"lib": ["ES5", "DOM"],

"strict": true,
"noEmitOnError": true,

"esModuleInterop": true,
"skipLibCheck": true,
Expand Down
20 changes: 14 additions & 6 deletions docs/ONBOARDING.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Onboarding

Disco has grown a lot since its early days, and like any sizeable code base, getting started is both
difficult and intimidating: there are a *lot* of files, it's not clear what's important at first, and even where to start
difficult and intimidating: there are a _lot_ of files, it's not clear what's important at first, and even where to start
is a bit of a puzzle. This document aims at giving you an efficient process to get familiar with DISCO.

The two main technologies behind DISCO are TypeScript and distributed machine learning. In the following sections I will assume that you are familiar
The two main technologies behind DISCO are TypeScript and distributed machine learning. In the following sections I will assume that you are familiar
with both to a certain extent. If not, the following references might be useful:

- [JavaScript](https://eloquentjavascript.net)
- [TypeScript](https://www.typescriptlang.org/docs/handbook/intro.html)
- [Federated and Decentralized Learning](https://arxiv.org/pdf/1912.04977)

> [!IMPORTANT]
> Disco is a big project and some information has probably been omitted or is outdated. It is now *your* responsibility to add missing information or let us know on [slack](https://join.slack.com/t/disco-decentralized/shared_invite/zt-fpsb7c9h-1M9hnbaSonZ7lAgJRTyNsw)!
> Disco is a big project and some information has probably been omitted or is outdated. It is now _your_ responsibility to add missing information or let us know on [slack](https://join.slack.com/t/disco-decentralized/shared_invite/zt-fpsb7c9h-1M9hnbaSonZ7lAgJRTyNsw)!
## First steps

Expand All @@ -22,7 +22,6 @@ a `server` and a `cli` (e.g., for benchmarking). Depending on what your goal is,
1. If you are going to work, contribute and improve the project, I first recommend you get a good understand of what DISCO does: play around with the [website](https://epfml.github.io/disco/#/), train a model from the pre-defined tasks, or even create your own custom task. Feedback is always appreciated, feel free to let us know on slack/in the github issues/in person if you noticed any issues or thought of an improvement.

2. Then, get a high-level understanding of the different parts of the projects in the [developer guide](../DEV.md), even if you're planning on working on a subset of the project. If you want to know more about a specific part of the project, refer to the table of contents at the end of the DEV guide.

3. Follow the installation instructions from the [developer guide](../DEV.md) to launch a DISCO instance working in your browser.

> [!TIP]
Expand All @@ -39,8 +38,17 @@ ts-node your_script.ts
```

* Because TypeScript needs to be transpiled to JavaScript, you need to rebuild the `discojs` folder every time you make any changes to it:
``` js
npm run build -w ./discojs
``` sh
npm -w ./discojs run build
```

If you want to automate the building phase, you can use the watch script in every project that run the given script when changes are detected.
As each of theses calls are non-terminating (theses are watching indefinitely), you'll need to run each in a different terminal.

```sh
npm -w ./discojs/discojs-core run watch build
npm -w ./discojs/discojs-node run watch build # another terminal
npm -w ./discojs/discojs-web run watch build # one more terminal
```

> [!TIP]
Expand Down
1 change: 0 additions & 1 deletion docs/node_example/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "../tsconfig.json",
"include": ["*.ts"],
"exclude": []
}
2 changes: 1 addition & 1 deletion docs/node_example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"typeRoots": ["node_modules/@types", "../../discojs/discojs-core/types"]
},
"include": ["*.ts"],
"exclude": ["node_modules"]
"exclude": ["**/*.spec.ts"]
}

Loading

0 comments on commit a42b435

Please sign in to comment.