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

Feat/fastapi #32

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
69871ed
added graph visualization from file
RanganThaya Jun 4, 2021
d304330
Merge pull request #30 from ai-systems/feat/graph_viz
RanganThaya Jun 4, 2021
45b283e
Merge pull request #31 from ai-systems/feat/from_splits
juliarozanova Aug 23, 2021
0c7c917
Upload config file
juliarozanova Aug 24, 2021
0ed8fb8
async results fetching after probing
juliarozanova Sep 7, 2021
9a23336
pivot to fastapi skeleton and include config loader
juliarozanova Nov 8, 2021
e8f9766
update tests for async functions
juliarozanova Nov 8, 2021
56f9c6b
refactor folder structure and update calls and tests
juliarozanova Nov 9, 2021
f2a81d4
move constants to module namespace
juliarozanova Nov 9, 2021
65633c0
resolve circular imports
juliarozanova Nov 9, 2021
7f8adee
typed dictionary setup
juliarozanova Nov 25, 2021
c91984e
include typed dictionaries for consistent probing inputs
juliarozanova Nov 26, 2021
c745312
make input reader multi-purpose for app coroutine or string file
juliarozanova Nov 29, 2021
4f08f0e
add config loader component
juliarozanova Nov 30, 2021
0a3fa83
tidy changes
juliarozanova Nov 30, 2021
40fd89a
Merge branch 'feat/fastapi' of github.com:ai-systems/Probe-Ably into …
juliarozanova Nov 30, 2021
493fbcc
delete old setup files
juliarozanova Nov 30, 2021
5957300
app tabs
juliarozanova Dec 1, 2021
b94b7cb
modularize config loaders
juliarozanova Dec 2, 2021
8679424
modularize config loaders
juliarozanova Dec 2, 2021
64ff416
reduce log messages and start redefining ProbingTask object
juliarozanova Dec 5, 2021
0c64c65
post submission update
juliarozanova Feb 10, 2022
0fface5
post submission update
juliarozanova Feb 10, 2022
7c199f6
ui spinner fixes
juliarozanova Feb 21, 2022
b075368
replace visualizations
juliarozanova Feb 22, 2022
3789b01
cancel extraneous progress fetching
juliarozanova Feb 22, 2022
82a6244
adjust test cases for new config syntax
juliarozanova Mar 7, 2022
e963c14
remove old prefect Task objects
juliarozanova Oct 7, 2023
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
16 changes: 0 additions & 16 deletions config/params/linear.json

This file was deleted.

32 changes: 0 additions & 32 deletions config/params/mlp.json

This file was deleted.

21 changes: 0 additions & 21 deletions config/probing_setup/default_probing_setup.json

This file was deleted.

3 changes: 0 additions & 3 deletions config/settings.toml

This file was deleted.

4 changes: 0 additions & 4 deletions docs/.buildinfo

This file was deleted.

31 changes: 26 additions & 5 deletions docsrc/quicktour.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Quick Start

## Application
We recommend using the browser-based application interface if you are new to probing.

Run the app using:
```
python -m probe_ably.app
```


## As a Python Library
Follow the installation guidelines.

### Default Probing Configuration
'''
from probe_ably import ProbingExperiment
experiment = ProbingExperiment.from_config("default")
experiment.representations = data # dataframe, torch tensor or np.array of vector representations
experiment.labels = labels # array-like
experiment.run()
'''

### Custom Probing Configuration

### Custom Probing Configuration with Data Paths

## CLI
## Representation File

The representation file that you are going to test in expected to be a tab seperated `tsv` file with one column for each dimension, separated by \t, last column is assumed to be the label.
Expand Down Expand Up @@ -67,8 +93,3 @@ In this configuration file.
At the end of the probe you will be directed or prompted to visit the following address: `http://127.0.0.1:8031/` where you can see the visualzation output.

By default probing will run the `Linear Model` and `MLP Model` with Accuracy and Selectivity as the default metrics. If you want to change the run configurations of these models see [Probing Configurations](/advanced/configurations.md).





10 changes: 0 additions & 10 deletions model3_test_control.tsv

This file was deleted.

1 change: 1 addition & 0 deletions probe_ably/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .experiment_setup import ProbingExperiment
13 changes: 13 additions & 0 deletions probe_ably/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import click
from probe_ably import ProbingExperiment

@click.command()
@click.option("--config_file",
help="Probing Configuration File",
default="./tests/sample_files/test_input/multi_task_multi_model_with_control.json")
def main(config_file):
experiment = ProbingExperiment.from_json(config_file)
experiment.run()

if __name__ == "__main__":
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
85 changes: 85 additions & 0 deletions probe_ably/app/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from probe_ably.metrics import ProcessMetricTask
from probe_ably.utils import ReadInputTask
from probe_ably.probing import TrainProbingTask
from probe_ably import ProbingExperiment
from pathlib import Path
import threading
import os

from fastapi import FastAPI, UploadFile, File, BackgroundTasks
from fastapi.staticfiles import StaticFiles
from fastapi.concurrency import run_in_threadpool
import uvicorn

app_dir = Path(os.path.abspath(__file__)).parent
build_dir = app_dir.joinpath('build')

# INPUT_FILE = "./tests/sample_files/test_input/multi_task_multi_model_with_control.json"
probing_task = TrainProbingTask()
read_input_task = ReadInputTask()
process_metric_task = ProcessMetricTask()


class ProbingThread(threading.Thread):
def __init__(self):
super().__init__()
self.results = None
self.task_loop_bar = None
self.reps_loop_bar = None
self.probes_loop_bar = None


async def set_config(self, config_file):
self.parsed_input = await read_input_task.run(config_file)


def run(self):
experiment = ProbingExperiment.from_parsed_input(self.parsed_input, thread=self)
results = experiment.run()
return results

app = FastAPI()
app.probing_thread = ProbingThread()


@app.post("/start_probing")
async def start_probing(background_tasks: BackgroundTasks, config_file: UploadFile = File(...), ):
await app.probing_thread.set_config(config_file)
results = await run_in_threadpool(app.probing_thread.run)
return results


@app.get('/model_progress')
def model_progress():
bar = app.probing_thread.reps_loop_bar
if bar:
prog = bar.format_dict
return prog
else:
return {'n': 0, 'total':0}


@app.get('/task_progress')
async def task_progress():
bar = app.probing_thread.task_loop_bar
if bar:
prog = bar.format_dict
return prog
else:
return {'n': 0, 'total':0}


@app.get('/probes_progress')
def probes_progress():
bar = app.probing_thread.probes_loop_bar
if bar:
prog = bar.format_dict
return prog
else:
return {'n': 0, 'total':0}


app.mount("/", StaticFiles(directory=build_dir, html = True), name="static")

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
22 changes: 11 additions & 11 deletions probe_ably/service/package.json → probe_ably/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"private": true,
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.3",
"@fortawesome/fontawesome-svg-core": "^1.2.35",
"@fortawesome/free-brands-svg-icons": "^5.15.3",
"@fortawesome/free-regular-svg-icons": "^5.15.3",
"@fortawesome/free-solid-svg-icons": "^5.15.3",
"@fortawesome/react-fontawesome": "^0.1.14",
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-brands-svg-icons": "^5.15.4",
"@fortawesome/free-regular-svg-icons": "^5.15.4",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"@fortawesome/react-fontawesome": "^0.1.15",
"@nivo/bar": "^0.73.1",
"@nivo/core": "^0.73.0",
"@nivo/line": "^0.73.0",
Expand All @@ -17,20 +17,21 @@
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.2.1",
"@themesberg/react-bootstrap": "^1.4.1",
"bootstrap": "5.0.2",
"bootstrap": "5.1.0",
"chartist": "^0.11.4",
"chartist-plugin-tooltips-updated": "^0.1.4",
"core-js": "^3.19.1",
"jspdf": "^2.3.1",
"moment-timezone": "^0.5.33",
"node-sass": "^6.0.1",
"react": "^17.0.2",
"react-chartist": "^0.14.4",
"react-copy-to-clipboard": "^5.0.3",
"react-copy-to-clipboard": "^5.0.4",
"react-datetime": "^3.0.4",
"react-dom": "^17.0.2",
"react-download-svg": "^0.0.4",
"react-github-btn": "^1.2.0",
"react-live": "^2.2.3",
"react-github-btn": "^1.2.1",
"react-live": "^2.3.0",
"react-router-dom": "^5.2.0",
"react-router-hash-link": "^2.4.3",
"react-scripts": "4.0.3",
Expand Down Expand Up @@ -63,6 +64,5 @@
"last 1 safari version"
]
},
"devDependencies": {
}
"devDependencies": {}
}
File renamed without changes.
File renamed without changes.
Binary file added probe_ably/app/src/assets/fireparrot.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { ResponsiveScatterPlot } from "@nivo/scatterplot";
import { ResponsiveLine } from '@nivo/line';
import {
Button,
ButtonGroup,
Card,
Col,
Row,
Row
} from "@themesberg/react-bootstrap";
import { jsPDF } from "jspdf";
import React, { useEffect, useRef } from "react";
import ReactDOM from "react-dom";
import "svg2pdf.js";


export default (props) => {
const { title, probing_data, task_name } = props;
const linechartRefs = useRef([]);
Expand Down Expand Up @@ -61,8 +62,8 @@ export default (props) => {
style={{ height: 400 }}
className="ct-series-g ct-major-tent"
>
<ResponsiveScatterPlot
colors={{ scheme: "accent" }}
<ResponsiveLine
colors={{ scheme: "category10" }}
data={p_data.chart_data}
margin={{ top: 60, right: 140, bottom: 70, left: 90 }}
xScale={{ type: "linear", min: "auto", max: "auto" }}
Expand All @@ -83,7 +84,8 @@ export default (props) => {
tickRotation: 90,
legend: p_data.x_axis,
legendPosition: "middle",
format: (value) => value.toExponential(2),
// format: (value) => value,
format: (value) => value < 0.001 || value > 10000 ? value.toExponential(2) : value,
legendOffset: 60,
}}
axisLeft={{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import HomePage from "./pages/HomePage";
// core styles
import "./scss/volt.scss";


ReactDOM.render(
<div>
{/* <ScrollToTop /> */}
Expand Down
File renamed without changes
57 changes: 57 additions & 0 deletions probe_ably/app/src/pages/HomePage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
Col, Container,
Navbar,
Row,
Spinner,
Card,
} from "@themesberg/react-bootstrap";

import React, { useEffect, useState } from "react";
import Report from "./dashboard/Report.js"
import ConfigDashboard from "./forms/ConfigDashboard";

export default () => {
const [isProbing, setIsProbing] = useState(false);
const [results, setResults] = useState(null);
const [taskProgress, setTaskProgress] = useState(0);
const [modelProgress, setModelProgress] = useState(0);
const [probesProgress, setProbesProgress] = useState(0);


const startProbing = async (formData) => {
setIsProbing(true);
await fetch("/start_probing", {method: "POST", body: formData})
.then(response => response.json())
.then(data => setResults(data));
setIsProbing(false);
}

return (
<div>
<Navbar
variant="dark"
expand="lg"
bg="dark"
className="navbar-transparent navbar-theme-primary my-2"
>
<Container>
<Navbar.Brand href="#" className="me-md-3" style={{ padding: 5 }}>
Probe_Ably
</Navbar.Brand>
</Container>
</Navbar>
<main style={{ padding: 21 }}>
<ConfigDashboard startProbing={startProbing}/>
<Report taskProgress={taskProgress}
modelProgress={modelProgress}
probesProgress={probesProgress}
setTaskProgress={setTaskProgress}
setModelProgress={setModelProgress}
setProbesProgress={setProbesProgress}
results={results}
isProbing={isProbing}>
</Report>
</main>
</div>
)
};
Loading