forked from mamba-org/resolvo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Taken from mamba-org#61 Co-authored-by: Bas Zalmstra <[email protected]> Signed-off-by: Julien Jerphanion <[email protected]>
- Loading branch information
Showing
3 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.csv | ||
.ipynb_checkpoints | ||
*/.ipynb_checkpoints/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ use std::{ | |
|
||
use clap::Parser; | ||
use csv::WriterBuilder; | ||
use resolvo::{snapshot::DependencySnapshot, Solver, UnsolvableOrCancelled}; | ||
use resolvo::{snapshot::DependencySnapshot, Problem, Solver, UnsolvableOrCancelled}; | ||
|
||
#[derive(Parser)] | ||
#[clap(version = "0.1.0", author = "Bas Zalmstra <[email protected]>")] | ||
|
@@ -27,7 +27,7 @@ fn main() { | |
let opts: Opts = Opts::parse(); | ||
|
||
eprintln!("Loading snapshot ..."); | ||
let snapshot_file = BufReader::new(File::open(&opts.snapshot).unwrap()); | ||
let snapshot_file = BufReader::new(File::open(opts.snapshot).unwrap()); | ||
let snapshot: DependencySnapshot = serde_json::from_reader(snapshot_file).unwrap(); | ||
|
||
let mut writer = WriterBuilder::new() | ||
|
@@ -50,7 +50,9 @@ fn main() { | |
let mut solver = Solver::new(provider); | ||
let mut records = None; | ||
let mut error = None; | ||
match solver.solve(vec![package_requirement.into()], vec![]) { | ||
|
||
let problem = Problem::default().requirements(vec![package_requirement.into()]); | ||
match solver.solve(problem) { | ||
Ok(solution) => { | ||
eprintln!("OK"); | ||
records = Some(solution.len()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e2ecd20f-bd4f-4a4a-82d0-28d2d9db18ac", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import polars as pl\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"\n", | ||
"plt.rcParams['figure.dpi'] = 300\n", | ||
"plt.rcParams['savefig.dpi'] = 300\n", | ||
"\n", | ||
"# These are all the timings we want to see\n", | ||
"paths = [\"main_timings.csv\", \"timings.csv\"]\n", | ||
"\n", | ||
"# Read the CSV\n", | ||
"dfs = [\n", | ||
" pl.scan_csv(path).select(pl.col(\"package\"), pl.col(\"duration\")).collect()\n", | ||
" for path in paths\n", | ||
"]\n", | ||
"\n", | ||
"# Define the histogram bins\n", | ||
"threshold = 10\n", | ||
"bins = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, threshold, threshold + 1]\n", | ||
"\n", | ||
"dfs_capped = [\n", | ||
" df.select([\n", | ||
" pl.col(\"duration\").map_elements(lambda x: min(x, threshold), return_dtype=pl.Float64)\n", | ||
" ]) for df in dfs]\n", | ||
"\n", | ||
"# Create the histogram\n", | ||
"fig, axs = plt.subplots(2, sharex=True)\n", | ||
"\n", | ||
"for path, df_capped, axs in zip(paths, dfs_capped, axs):\n", | ||
" axs.hist(df_capped[\"duration\"], bins=bins, density=True)\n", | ||
" axs.set_title(path)\n", | ||
"\n", | ||
"# Add labels to the ticks\n", | ||
"fig.supxlabel(\"Duration in seconds\")\n", | ||
"fig.supylabel(\"Percantage of succesful solves\")\n", | ||
"fig.suptitle(\"Histogram of solve durations\")\n", | ||
"\n", | ||
"plt.show()\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "88f7081d-d2bf-4fb7-86ab-7fd22dce0202", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"paths = [\"timings.csv\", \"main_timings.csv\"]\n", | ||
"\n", | ||
"# Load the timings\n", | ||
"dfs = [\n", | ||
" pl.scan_csv(path).select(pl.col(\"package\"), pl.col(\"duration\")) \n", | ||
" for path in paths\n", | ||
"]\n", | ||
"\n", | ||
"# Compute the solver diffs\n", | ||
"df_diff = dfs[0].join(dfs[1], on=\"package\").select(pl.col(\"package\"), (pl.col(\"duration\")-pl.col(\"duration_right\"))).collect();\n", | ||
"\n", | ||
"# Create the histogram\n", | ||
"plt.hist(df_diff[\"duration\"], bins=40, density=True)\n", | ||
"\n", | ||
"plt.show()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.5" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |