Skip to content

Commit

Permalink
experiment: use cached packages
Browse files Browse the repository at this point in the history
  • Loading branch information
nichmor committed Jun 14, 2024
1 parent 9a33a80 commit a504c47
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
8 changes: 6 additions & 2 deletions crates/rattler_solve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub mod libsolv_c;
#[cfg(feature = "resolvo")]
pub mod resolvo;

use std::fmt;
use std::{collections::HashMap, fmt};

use chrono::{DateTime, Utc};
use rattler_conda_types::{GenericVirtualPackage, MatchSpec, RepoDataRecord};
use rattler_conda_types::{GenericVirtualPackage, MatchSpec, PackageName, RepoDataRecord, Version};

/// Represents a solver implementation, capable of solving [`SolverTask`]s
pub trait SolverImpl {
Expand Down Expand Up @@ -149,6 +149,9 @@ pub struct SolverTask<TAvailablePackagesIterator> {

/// The solve strategy.
pub strategy: SolveStrategy,

/// Cached packages.
pub cached_packages: HashMap<PackageName, Version>,
}

impl<'r, I: IntoIterator<Item = &'r RepoDataRecord>> FromIterator<I>
Expand All @@ -166,6 +169,7 @@ impl<'r, I: IntoIterator<Item = &'r RepoDataRecord>> FromIterator<I>
channel_priority: ChannelPriority::default(),
exclude_newer: None,
strategy: SolveStrategy::default(),
cached_packages: Default::default(),
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion crates/rattler_solve/src/resolvo/conda_util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{cmp::Ordering, collections::HashMap};

use futures::future::FutureExt;
use rattler_conda_types::Version;
use rattler_conda_types::{PackageName, Version};
use resolvo::{Dependencies, SolvableId, SolverCache, VersionSetId};

use crate::resolvo::CondaDependencyProvider;
Expand All @@ -23,6 +23,7 @@ pub(super) fn compare_candidates(
Option<(rattler_conda_types::Version, bool)>,

Check warning on line 23 in crates/rattler_solve/src/resolvo/conda_util.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/src/resolvo/conda_util.rs
>,
strategy: CompareStrategy,
cached_versions: HashMap<PackageName, Version>
) -> Ordering {
let pool = &solver.provider().pool;

Expand All @@ -42,6 +43,24 @@ pub(super) fn compare_candidates(
Ordering::Equal => {}
};

// Check if either version is in the cached versions set

Check warning on line 46 in crates/rattler_solve/src/resolvo/conda_util.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/src/resolvo/conda_util.rs
let some_cached_version = cached_versions.get(a_record.name());
tracing::error!("cached_version: {:?}", cached_versions);
if let Some(cc) = some_cached_version{
tracing::error!("cached_version: {:?}", cc);
}
if let Some(cached_version) = some_cached_version{
let a_is_cached = cached_version == a_record.version();
let b_is_cached = cached_version == b_record.version();
match a_is_cached.cmp(&b_is_cached) {
Ordering::Greater => return Ordering::Less,
Ordering::Less => return Ordering::Greater,

Check warning on line 57 in crates/rattler_solve/src/resolvo/conda_util.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/src/resolvo/conda_util.rs
Ordering::Equal => {}
}

}


// Otherwise, select the variant with the highest version
match (strategy, a_record.version().cmp(b_record.version())) {
(CompareStrategy::Default, Ordering::Greater)
Expand Down
13 changes: 11 additions & 2 deletions crates/rattler_solve/src/resolvo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
collections::{HashMap, HashSet},

Check warning on line 6 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/src/resolvo/mod.rs
fmt::{Display, Formatter},
marker::PhantomData,
ops::Deref,
ops::Deref, str::FromStr,
};

use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -174,6 +174,8 @@ pub struct CondaDependencyProvider<'a> {
strategy: SolveStrategy,

Check warning on line 175 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/src/resolvo/mod.rs
direct_dependencies: HashSet<NameId>,

cached_versions: HashMap<PackageName, rattler_conda_types::Version>
}

impl<'a> CondaDependencyProvider<'a> {
Expand All @@ -189,6 +191,7 @@ impl<'a> CondaDependencyProvider<'a> {
channel_priority: ChannelPriority,
exclude_newer: Option<DateTime<Utc>>,
strategy: SolveStrategy,
cached_versions: HashMap<PackageName, rattler_conda_types::Version>,

Check failure on line 194 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Check intra-doc links

unused variable: `cached_versions`

Check failure on line 194 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format, Lint and Test the Python bindings

unused variable: `cached_versions`
) -> Result<Self, SolveError> {
let pool = Pool::default();
let mut records: HashMap<NameId, Candidates> = HashMap::default();
Expand Down Expand Up @@ -390,6 +393,10 @@ impl<'a> CondaDependencyProvider<'a> {
candidates.locked = Some(solvable);

Check warning on line 393 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/src/resolvo/mod.rs
}

let cached_versions = HashMap::from([
(PackageName::try_from("boltons").unwrap(), rattler_conda_types::Version::from_str("21.0.0").unwrap()),
]);

Ok(Self {
pool,
records,
Expand All @@ -398,6 +405,7 @@ impl<'a> CondaDependencyProvider<'a> {
stop_time,
strategy,
direct_dependencies,
cached_versions,
})
}

Expand Down Expand Up @@ -478,7 +486,7 @@ impl<'a> DependencyProvider for CondaDependencyProvider<'a> {
}

Check warning on line 486 in crates/rattler_solve/src/resolvo/mod.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/rattler/rattler/crates/rattler_solve/src/resolvo/mod.rs
};
solvables.sort_by(|&p1, &p2| {
conda_util::compare_candidates(p1, p2, solver, &mut highest_version_spec, strategy)
conda_util::compare_candidates(p1, p2, solver, &mut highest_version_spec, strategy, self.cached_versions.clone())
});
}

Expand Down Expand Up @@ -608,6 +616,7 @@ impl super::SolverImpl for Solver {
task.channel_priority,
task.exclude_newer,
task.strategy,
task.cached_packages.clone(),
)?;

// Construct the requirements that the solver needs to satisfy.
Expand Down

0 comments on commit a504c47

Please sign in to comment.