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

[WIP] experiment: use cached packages #749

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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: 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 @@ -20,9 +20,10 @@
solver: &SolverCache<CondaDependencyProvider<'_>>,
match_spec_highest_version: &mut HashMap<
VersionSetId,
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 @@
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 @@ -3,10 +3,10 @@
use std::{
cell::RefCell,
cmp::Ordering,
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 @@ -172,8 +172,10 @@
stop_time: Option<std::time::SystemTime>,

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 @@
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 @@ -387,9 +390,13 @@
let solvable = pool.intern_solvable(name, SolverPackageRecord::Record(locked_record));
let candidates = records.entry(name).or_default();
candidates.candidates.push(solvable);
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 @@
stop_time,
strategy,
direct_dependencies,
cached_versions,
})
}

Expand Down Expand Up @@ -475,10 +483,10 @@
} else {
CompareStrategy::Default
}
}

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 @@
task.channel_priority,
task.exclude_newer,
task.strategy,
task.cached_packages.clone(),
)?;

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