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

fix: skip deserialization, just use a &str #519

Merged
merged 2 commits into from
Jul 22, 2024
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
2 changes: 1 addition & 1 deletion martian-lab/examples/sum_sq/src/sum_squares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl MartianStage for SumSquares {
for value in args.values {
let chunk_inputs = SumSquaresChunkInputs { value };
// It is optional to create a chunk with resource. If not specified, default resource will be used
stage_def.add_chunk_with_resource(chunk_inputs, chunk_resource.clone());
stage_def.add_chunk_with_resource(chunk_inputs, chunk_resource);
}
// Return the stage definition
Ok(stage_def)
Expand Down
22 changes: 13 additions & 9 deletions martian/src/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,20 @@ impl<T: MartianFileType> MartianMakePath for T {
///
/// Memory/ thread request can be negative in matrian. See
/// [http://martian-lang.org/advanced-features/#resource-consumption](http://martian-lang.org/advanced-features/#resource-consumption)
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[derive(Debug, Serialize, Deserialize, Copy, Clone, Default)]
pub struct Resource {
#[serde(rename = "__mem_gb", skip_serializing_if = "Option::is_none")]
mem_gb: Option<isize>,
#[serde(rename = "__threads", skip_serializing_if = "Option::is_none")]
threads: Option<isize>,
#[serde(rename = "__vmem_gb", skip_serializing_if = "Option::is_none")]
vmem_gb: Option<isize>,
#[serde(rename = "__special", skip_serializing_if = "Option::is_none")]
special: Option<String>,
#[serde(
rename = "__special",
skip_serializing_if = "Option::is_none",
skip_deserializing
)]
special: Option<&'static str>,
}

impl Resource {
Expand Down Expand Up @@ -167,8 +171,8 @@ impl Resource {
}

/// Get the special resource request
pub fn get_special(&self) -> Option<String> {
self.special.clone()
pub fn get_special(&self) -> Option<&'static str> {
self.special
}

/// Set the mem_gb
Expand Down Expand Up @@ -217,13 +221,13 @@ impl Resource {
/// ```rust
/// use martian::Resource;
///
/// let resource = Resource::new().mem_gb(2).vmem_gb(4).special("gpu_count1_mem8".to_owned());
/// let resource = Resource::new().mem_gb(2).vmem_gb(4).special("gpu_count1_mem8");
/// assert_eq!(resource.get_mem_gb(), Some(2));
/// assert_eq!(resource.get_vmem_gb(), Some(4));
/// assert_eq!(resource.get_threads(), None);
/// assert_eq!(resource.get_special(), Some("gpu_count1_mem8".to_owned()));
/// assert_eq!(resource.get_special(), Some("gpu_count1_mem8"));
/// ```
pub fn special(mut self, special: String) -> Self {
pub fn special(mut self, special: &'static str) -> Self {
self.special = Some(special);
self
}
Expand Down Expand Up @@ -633,7 +637,7 @@ pub trait MartianStage: MroMaker {
fill_defaults(resource),
))
}
let rover = _chunk_prelude(chunk_idx, run_directory, chunk.resource.clone())?;
let rover = _chunk_prelude(chunk_idx, run_directory, chunk.resource)?;
self.main(args.clone(), chunk.inputs.clone(), rover)
};

Expand Down
Loading