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

Documentation: Edit src/syft.js #195

Merged
merged 2 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions API-REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ Syft client for static federated learning.
const client = new Syft({url: "ws://localhost:5000", verbose: true})
const job = client.newJob({modelName: "mnist", modelVersion: "1.0.0"})
job.on('accepted', async ({model, clientConfig}) => {
// execute training
// Execute training
const [...newParams] = await this.plans['...'].execute(...)
const diff = await model.createSerializedDiff(newParams)
await this.report(diff)
})
job.on('rejected', ({timeout}) => {
// re-try later or stop
// Retry later or stop
})
job.on('error', (err) => {
// handle errors
// Handle errors
})
job.start()
```
Expand All @@ -70,7 +70,7 @@ Authenticates the client against PyGrid and instantiates new Job with given opti
- `options.modelVersion` **[string][26]** FL Model version.


- Throws **any** Error
- Throws **any** Error if grid client authentication failed.

Returns **[Promise][28]<[Job][29]>**

Expand Down
33 changes: 16 additions & 17 deletions src/syft.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,42 @@ import ObjectRegistry from './object-registry';
* Syft client for static federated learning.
*
* @param {Object} options
* @param {string} options.url Full URL to PyGrid app (`ws` and `http` schemas supported).
* @param {boolean} options.verbose Whether to enable logging and allow unsecured PyGrid connection.
* @param {string} options.authToken PyGrid authentication token.
* @param {Object} options.peerConfig [not implemented] WebRTC peer config used with RTCPeerConnection.
* @param {string} options.url - Full URL to PyGrid app (`ws` and `http` schemas supported).
* @param {boolean} options.verbose - Whether to enable logging and allow unsecured PyGrid connection.
* @param {string} options.authToken - PyGrid authentication token.
* @param {Object} options.peerConfig - [not implemented] WebRTC peer config used with RTCPeerConnection.
*
* @example
*
* const client = new Syft({url: "ws://localhost:5000", verbose: true})
* const job = client.newJob({modelName: "mnist", modelVersion: "1.0.0"})
* job.on('accepted', async ({model, clientConfig}) => {
* // execute training
* // Execute training
* const [...newParams] = await this.plans['...'].execute(...)
* const diff = await model.createSerializedDiff(newParams)
* await this.report(diff)
* })
* job.on('rejected', ({timeout}) => {
* // re-try later or stop
* // Retry later or stop
* })
* job.on('error', (err) => {
* // handle errors
* // Handle errors
* })
* job.start()
*/
export default class Syft {
constructor({ url, verbose, authToken, peerConfig }) {
// For creating verbose logging should the worker desire
// Create verbose logging if verbose value is true
this.logger = new Logger('syft.js', verbose);

// Forcing connection to be secure if verbose value is false.
// Force connection to be secure if verbose value is false
this.verbose = verbose;

this.gridClient = new GridAPIClient({ url, allowInsecureUrl: verbose });

// objects registry
// Create objects registry
this.objects = new ObjectRegistry();

// For creating event listeners
// Create event listeners
this.observer = new EventObserver();

this.worker_id = null;
Expand All @@ -56,15 +55,15 @@ export default class Syft {
/**
* Authenticates the client against PyGrid and instantiates new Job with given options.
*
* @throws Error
* @throws Error if grid client authentication failed.
* @param {Object} options
* @param {string} options.modelName FL Model name.
* @param {string} options.modelVersion FL Model version.
* @param {string} options.modelName - FL Model name.
* @param {string} options.modelVersion - FL Model version.
* @returns {Promise<Job>}
*/
async newJob({ modelName, modelVersion }) {
if (!this.worker_id) {
// authenticate
// Authenticate the client
const authResponse = await this.gridClient.authenticate(
modelName,
modelVersion,
Expand All @@ -78,7 +77,7 @@ export default class Syft {
worker: this,
modelName,
modelVersion,
gridClient: this.gridClient
gridClient: this.gridClient,
});
}
}