optirs-core 0.3.1

OptiRS core optimization algorithms and utilities
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
// Academic Research Collaboration Framework
//
// This module provides comprehensive tools for academic researchers to collaborate,
// reproduce experiments, track results, and generate publications using SciRS2 optimizers.
//
// # Features
//
// - **Experiment Tracking**: Comprehensive tracking of experimental configurations and results
// - **Reproducibility**: Tools to ensure experiments can be reproduced exactly
// - **Publication Generation**: Automated LaTeX/Markdown report generation
// - **Citation Management**: BibTeX integration and automated citations
// - **Benchmark Suite**: Standardized academic benchmarks
// - **Collaboration Tools**: Multi-researcher project management
// - **Conference Integration**: Templates and tools for academic conferences
// - **Peer Review Support**: Anonymous review and feedback systems
//
// # Examples
//
// ## Setting up a Research Project
//
// ```rust
// use optirs_core::research::*;
//
// let project = ResearchProject::new("Neural Optimizer Comparison")
//     .add_researcher("Dr. Alice Smith", "alice@university.edu")
//     .add_researcher("Prof. Bob Johnson", "bob@institute.org")
//     .set_research_area(ResearchArea::MachineLearning)
//     .set_funding_source("NSF Grant #12345")
//     .enable_reproducibility_tracking(true);
//
// // Setup experiment tracking
// let experiment = Experiment::new("Adam vs SGD Comparison")
//     .set_hypothesis("Adam converges faster than SGD on deep networks")
//     .add_optimizer_config("adam", adam_config)
//     .add_optimizer_config("sgd", sgd_config)
//     .set_dataset("CIFAR-10")
//     .set_metrics(vec!["accuracy", "convergence_rate", "training_time"]);
// ```

pub mod benchmarks;
pub mod citations;
pub mod collaboration;
pub mod conferences;
pub mod datasets;
pub mod experiments;
pub mod funding;
pub mod peer_review;
pub mod publications;
pub mod reproducibility;

// Re-exports for convenience - using selective exports to avoid conflicts
pub use benchmarks::*;
pub use collaboration::*;
pub use datasets::*;
pub use funding::*;

// Selective re-exports for experiments to avoid conflicts
pub use experiments::{
    CpuInfo, DataType, DatasetInfo, DatasetStatistics, EarlyStoppingConfig, Experiment,
    ExperimentConfig, ExperimentMetadata, ExperimentNote, ExperimentResult, ExperimentRunner,
    ExperimentStatus, ExperimentTimeline, GpuInfo, HardwareConfig as ExperimentHardwareConfig,
    MemoryAllocationStrategy, MemoryConfig, NoteType, OptimizationMode, ParallelConfig,
    PreprocessingStep, ReproducibilityChecklist, ReproducibilityInfo, ResourceMonitor,
    ResourceUsage, RunStatus, SystemInfo as ExperimentSystemInfo, TrainingHistory,
};

// Selective re-exports for reproducibility to avoid conflicts
pub use reproducibility::{
    CpuSpec, Dependency, Difference, DifferenceCategory, EnvironmentSnapshot, GpuSpec,
    HardwareConfig as ReproducibilityHardwareConfig, IssueSeverity, IssueType, MemorySpec,
    ReproducibilityChecklist as ReproducibilityChecklistType, ReproducibilityConfig,
    ReproducibilityIssue, ReproducibilityManager, ReproducibilityReport, ReproducibilityStorage,
    SimilarityMetrics, StorageSpec, SystemInfo as ReproducibilitySystemInfo, VerificationResult,
    VerificationStatus,
};

// Selective re-exports to avoid conflicts
// Citations module exports
pub use citations::{
    Author as CitationAuthor, BibliographyFormat, Citation, CitationManager,
    CitationStyle as CitationStyleType, DateFormat, FormattingRules, InTextFormat, NameFormat,
    PublicationType as CitationPublicationType, PunctuationRules, SortDirection, SortField,
    SortingRules, TitleFormat,
};

// Publications module exports
pub use publications::{
    Affiliation, Author as PublicationAuthor, AuthorPosition, BibTeXEntry, Bibliography,
    CitationStyle as PublicationCitationStyle, Decision, Figure, FigureType, ManuscriptSection,
    Publication, PublicationStatus, PublicationType as PublicationTypeEnum,
    Review as PublicationReview, ReviewRecommendation as PublicationReviewRecommendation,
    ReviewerInfo, SectionType, SubmissionRecord, SubmissionStatus, Table, Venue, VenueType,
};

// Peer review module exports
pub use peer_review::{
    MetaReview, PeerReview, PeerReviewSystem, ReviewAssignment, ReviewCriterion, ReviewDiscussion,
    ReviewQualityAssessment, ReviewQualityMetric, ReviewRecommendation as PeerReviewRecommendation,
    ReviewSession, ReviewSessionStatus, ReviewStatus, ReviewType, Reviewer, ReviewerAvailability,
    ReviewerHistory, ReviewerPreferences, ReviewerQualityMetrics, WrittenReview,
};

// Conferences module exports
pub use conferences::{
    Conference, ConferenceDates, ConferenceManager, DeadlineType, Review as ConferenceReview,
    ReviewFormat, ReviewProcess, ReviewRecommendation as ConferenceReviewRecommendation,
    Submission, SubmissionStatus as ConferenceSubmissionStatus,
};

use crate::error::{OptimError, Result};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;

/// Main research project coordinator
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResearchProject {
    /// Project name
    pub name: String,
    /// Project description
    pub description: String,
    /// Research area classification
    pub research_area: ResearchArea,
    /// Project status
    pub status: ProjectStatus,
    /// List of researchers
    pub researchers: Vec<Researcher>,
    /// Funding information
    pub funding: Option<FundingInfo>,
    /// Project timeline
    pub timeline: ProjectTimeline,
    /// Experiments in this project
    pub experiments: Vec<Experiment>,
    /// Publications related to this project
    pub publications: Vec<Publication>,
    /// Project settings
    pub settings: ProjectSettings,
    /// Creation timestamp
    pub created_at: DateTime<Utc>,
    /// Last modified timestamp
    pub modified_at: DateTime<Utc>,
}

/// Research area classifications
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ResearchArea {
    /// Machine Learning
    MachineLearning,
    /// Deep Learning
    DeepLearning,
    /// Optimization Theory
    OptimizationTheory,
    /// Computer Vision
    ComputerVision,
    /// Natural Language Processing
    NaturalLanguageProcessing,
    /// Reinforcement Learning
    ReinforcementLearning,
    /// Scientific Computing
    ScientificComputing,
    /// High Performance Computing
    HighPerformanceComputing,
    /// Distributed Systems
    DistributedSystems,
    /// Quantum Computing
    QuantumComputing,
    /// Interdisciplinary
    Interdisciplinary,
    /// Other with description
    Other(String),
}

/// Project status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ProjectStatus {
    /// Planning phase
    Planning,
    /// Active research
    Active,
    /// Data collection
    DataCollection,
    /// Analysis phase
    Analysis,
    /// Writing phase
    Writing,
    /// Under review
    UnderReview,
    /// Published
    Published,
    /// Completed
    Completed,
    /// On hold
    OnHold,
    /// Cancelled
    Cancelled,
}

/// Researcher information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Researcher {
    /// Full name
    pub name: String,
    /// Email address
    pub email: String,
    /// Institution/affiliation
    pub affiliation: String,
    /// ORCID identifier
    pub orcid: Option<String>,
    /// Role in the project
    pub role: ResearcherRole,
    /// Expertise areas
    pub expertise: Vec<String>,
    /// Contact information
    pub contact_info: ContactInfo,
}

/// Researcher roles
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ResearcherRole {
    /// Principal Investigator
    PrincipalInvestigator,
    /// Co-Principal Investigator
    CoPrincipalInvestigator,
    /// Senior Researcher
    SeniorResearcher,
    /// Postdoc
    Postdoc,
    /// PhD Student
    PhDStudent,
    /// Masters Student
    MastersStudent,
    /// Undergraduate Student
    UndergraduateStudent,
    /// Research Assistant
    ResearchAssistant,
    /// Collaborator
    Collaborator,
    /// Advisor
    Advisor,
}

/// Contact information
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ContactInfo {
    /// Phone number
    pub phone: Option<String>,
    /// Office address
    pub office_address: Option<String>,
    /// Mailing address
    pub mailing_address: Option<String>,
    /// Website/homepage
    pub website: Option<String>,
    /// Social media handles
    pub social_media: HashMap<String, String>,
}

/// Funding information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FundingInfo {
    /// Funding agency
    pub agency: String,
    /// Grant number
    pub grant_number: String,
    /// Grant title
    pub grant_title: String,
    /// Total amount
    pub amount: Option<f64>,
    /// Currency
    pub currency: String,
    /// Start date
    pub start_date: DateTime<Utc>,
    /// End date
    pub end_date: DateTime<Utc>,
    /// Award date
    pub award_date: Option<DateTime<Utc>>,
}

/// Project timeline
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProjectTimeline {
    /// Project start date
    pub start_date: DateTime<Utc>,
    /// Planned end date
    pub planned_end_date: DateTime<Utc>,
    /// Actual end date
    pub actual_end_date: Option<DateTime<Utc>>,
    /// Key milestones
    pub milestones: Vec<Milestone>,
    /// Progress updates
    pub progress_updates: Vec<ProgressUpdate>,
}

/// Project milestone
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Milestone {
    /// Milestone name
    pub name: String,
    /// Description
    pub description: String,
    /// Planned date
    pub planned_date: DateTime<Utc>,
    /// Actual completion date
    pub completed_date: Option<DateTime<Utc>>,
    /// Status
    pub status: MilestoneStatus,
    /// Deliverables
    pub deliverables: Vec<String>,
}

/// Milestone status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum MilestoneStatus {
    /// Not started
    NotStarted,
    /// In progress
    InProgress,
    /// Completed
    Completed,
    /// Delayed
    Delayed,
    /// Cancelled
    Cancelled,
}

/// Progress update
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProgressUpdate {
    /// Update timestamp
    pub timestamp: DateTime<Utc>,
    /// Update author
    pub author: String,
    /// Progress summary
    pub summary: String,
    /// Detailed description
    pub description: String,
    /// Percentage completion
    pub completion_percentage: f64,
    /// Next steps
    pub next_steps: Vec<String>,
    /// Challenges encountered
    pub challenges: Vec<String>,
}

/// Project settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProjectSettings {
    /// Enable reproducibility tracking
    pub enable_reproducibility: bool,
    /// Enable automatic backups
    pub enable_backups: bool,
    /// Backup frequency (hours)
    pub backup_frequency_hours: u32,
    /// Data retention policy (days)
    pub data_retention_days: u32,
    /// Privacy settings
    pub privacy_settings: PrivacySettings,
    /// Collaboration settings
    pub collaboration_settings: CollaborationSettings,
    /// Publication settings
    pub publication_settings: PublicationSettings,
}

/// Privacy settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PrivacySettings {
    /// Project visibility
    pub visibility: ProjectVisibility,
    /// Data sharing policy
    pub data_sharing: DataSharingPolicy,
    /// Enable anonymous access
    pub allow_anonymous_access: bool,
    /// Embargo period (days)
    pub embargo_period_days: Option<u32>,
}

/// Project visibility
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum ProjectVisibility {
    /// Public - visible to everyone
    Public,
    /// Internal - visible to institution members
    Internal,
    /// Private - visible to project members only
    Private,
    /// Restricted - invitation only
    Restricted,
}

/// Data sharing policy
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum DataSharingPolicy {
    /// Open data - freely available
    Open,
    /// On request - available upon request
    OnRequest,
    /// Restricted - limited sharing
    Restricted,
    /// No sharing - private data only
    NoSharing,
}

/// Collaboration settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CollaborationSettings {
    /// Enable real-time collaboration
    pub enable_realtime_collaboration: bool,
    /// Enable version control
    pub enable_version_control: bool,
    /// Enable peer review
    pub enable_peer_review: bool,
    /// Enable discussion forums
    pub enable_discussions: bool,
    /// Maximum collaborators
    pub max_collaborators: Option<u32>,
}

/// Publication settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PublicationSettings {
    /// Default publication format
    pub default_format: PublicationFormat,
    /// Enable automatic citations
    pub enable_auto_citations: bool,
    /// Citation style
    pub citation_style: CitationStyle,
    /// Enable preprint submission
    pub enable_preprints: bool,
    /// Target conferences/journals
    pub target_venues: Vec<String>,
}

/// Publication formats
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum PublicationFormat {
    /// LaTeX
    LaTeX,
    /// Markdown
    Markdown,
    /// HTML
    Html,
    /// PDF
    Pdf,
    /// Word Document
    Word,
    /// Jupyter Notebook
    Notebook,
}

/// Citation styles
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum CitationStyle {
    /// APA style
    APA,
    /// IEEE style
    IEEE,
    /// ACM style
    ACM,
    /// Nature style
    Nature,
    /// Science style
    Science,
    /// Custom BibTeX style
    Custom(String),
}

/// Research project manager
#[derive(Debug)]
pub struct ResearchProjectManager {
    /// Active projects
    projects: HashMap<String, ResearchProject>,
    /// Project storage directory
    storage_dir: PathBuf,
    /// Manager settings
    settings: ManagerSettings,
}

/// Manager settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ManagerSettings {
    /// Default project template
    pub default_template: Option<String>,
    /// Auto-save frequency (minutes)
    pub auto_save_frequency: u32,
    /// Enable cloud backup
    pub enable_cloud_backup: bool,
    /// Cloud storage provider
    pub cloud_provider: Option<String>,
    /// Notification settings
    pub notifications: NotificationSettings,
}

/// Notification settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NotificationSettings {
    /// Email notifications enabled
    pub email_enabled: bool,
    /// Slack notifications enabled
    pub slack_enabled: bool,
    /// Webhook URL for notifications
    pub webhook_url: Option<String>,
    /// Notification frequency
    pub frequency: NotificationFrequency,
}

/// Notification frequency
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum NotificationFrequency {
    /// Real-time notifications
    Realtime,
    /// Daily digest
    Daily,
    /// Weekly digest
    Weekly,
    /// Monthly digest
    Monthly,
    /// On important events only
    Important,
    /// Disabled
    Disabled,
}

impl ResearchProject {
    /// Create a new research project
    pub fn new(name: &str) -> Self {
        let now = Utc::now();
        Self {
            name: name.to_string(),
            description: String::new(),
            research_area: ResearchArea::MachineLearning,
            status: ProjectStatus::Planning,
            researchers: Vec::new(),
            funding: None,
            timeline: ProjectTimeline {
                start_date: now,
                planned_end_date: now + chrono::Duration::days(365),
                actual_end_date: None,
                milestones: Vec::new(),
                progress_updates: Vec::new(),
            },
            experiments: Vec::new(),
            publications: Vec::new(),
            settings: ProjectSettings::default(),
            created_at: now,
            modified_at: now,
        }
    }

    /// Set project description
    pub fn description(mut self, description: &str) -> Self {
        self.description = description.to_string();
        self.modified_at = Utc::now();
        self
    }

    /// Set research area
    pub fn research_area(mut self, area: ResearchArea) -> Self {
        self.research_area = area;
        self.modified_at = Utc::now();
        self
    }

    /// Add a researcher to the project
    pub fn add_researcher(mut self, name: &str, email: &str) -> Self {
        let researcher = Researcher {
            name: name.to_string(),
            email: email.to_string(),
            affiliation: String::new(),
            orcid: None,
            role: ResearcherRole::Collaborator,
            expertise: Vec::new(),
            contact_info: ContactInfo::default(),
        };
        self.researchers.push(researcher);
        self.modified_at = Utc::now();
        self
    }

    /// Set funding information
    pub fn funding(mut self, funding: FundingInfo) -> Self {
        self.funding = Some(funding);
        self.modified_at = Utc::now();
        self
    }

    /// Enable reproducibility tracking
    pub fn enable_reproducibility(mut self, enabled: bool) -> Self {
        self.settings.enable_reproducibility = enabled;
        self.modified_at = Utc::now();
        self
    }

    /// Add an experiment to the project
    pub fn add_experiment(&mut self, experiment: Experiment) -> Result<()> {
        self.experiments.push(experiment);
        self.modified_at = Utc::now();
        Ok(())
    }

    /// Add a publication to the project
    pub fn add_publication(&mut self, publication: Publication) -> Result<()> {
        self.publications.push(publication);
        self.modified_at = Utc::now();
        Ok(())
    }

    /// Generate project summary report
    pub fn generate_summary_report(&self) -> String {
        let mut report = String::new();

        report.push_str(&format!("# {}\n\n", self.name));
        report.push_str(&format!("**Description**: {}\n\n", self.description));
        report.push_str(&format!("**Research Area**: {:?}\n\n", self.research_area));
        report.push_str(&format!("**Status**: {:?}\n\n", self.status));

        report.push_str("## Researchers\n\n");
        for researcher in &self.researchers {
            report.push_str(&format!(
                "- {} ({}) - {:?}\n",
                researcher.name, researcher.email, researcher.role
            ));
        }

        if let Some(funding) = &self.funding {
            report.push_str("\n## Funding\n\n");
            report.push_str(&format!("**Agency**: {}\n", funding.agency));
            report.push_str(&format!("**Grant**: {}\n", funding.grant_number));
            if let Some(amount) = funding.amount {
                report.push_str(&format!("**Amount**: {:.2} {}\n", amount, funding.currency));
            }
        }

        report.push_str("\n## Progress\n\n");
        report.push_str(&format!("**Experiments**: {}\n", self.experiments.len()));
        report.push_str(&format!("**Publications**: {}\n", self.publications.len()));
        report.push_str(&format!(
            "**Milestones**: {}\n",
            self.timeline.milestones.len()
        ));

        report
    }
}

impl Default for ProjectSettings {
    fn default() -> Self {
        Self {
            enable_reproducibility: true,
            enable_backups: true,
            backup_frequency_hours: 24,
            data_retention_days: 1095, // 3 years
            privacy_settings: PrivacySettings::default(),
            collaboration_settings: CollaborationSettings::default(),
            publication_settings: PublicationSettings::default(),
        }
    }
}

impl Default for PrivacySettings {
    fn default() -> Self {
        Self {
            visibility: ProjectVisibility::Private,
            data_sharing: DataSharingPolicy::OnRequest,
            allow_anonymous_access: false,
            embargo_period_days: Some(365),
        }
    }
}

impl Default for CollaborationSettings {
    fn default() -> Self {
        Self {
            enable_realtime_collaboration: true,
            enable_version_control: true,
            enable_peer_review: true,
            enable_discussions: true,
            max_collaborators: Some(20),
        }
    }
}

impl Default for PublicationSettings {
    fn default() -> Self {
        Self {
            default_format: PublicationFormat::LaTeX,
            enable_auto_citations: true,
            citation_style: CitationStyle::IEEE,
            enable_preprints: true,
            target_venues: Vec::new(),
        }
    }
}

impl ResearchProjectManager {
    /// Create a new research project manager
    pub fn new(storage_dir: PathBuf) -> Result<Self> {
        std::fs::create_dir_all(&storage_dir)?;

        Ok(Self {
            projects: HashMap::new(),
            storage_dir,
            settings: ManagerSettings::default(),
        })
    }

    /// Create a new research project
    pub fn create_project(&mut self, name: &str) -> Result<&mut ResearchProject> {
        if self.projects.contains_key(name) {
            return Err(OptimError::InvalidConfig(format!(
                "Project '{}' already exists",
                name
            )));
        }

        let project = ResearchProject::new(name);
        self.projects.insert(name.to_string(), project);
        self.save_project(name)?;

        Ok(self.projects.get_mut(name).expect("unwrap failed"))
    }

    /// Load an existing project
    pub fn load_project(&mut self, name: &str) -> Result<&mut ResearchProject> {
        if !self.projects.contains_key(name) {
            let project_file = self.storage_dir.join(format!("{}.json", name));
            if project_file.exists() {
                let content = std::fs::read_to_string(&project_file)?;
                let project: ResearchProject = serde_json::from_str(&content)?;
                self.projects.insert(name.to_string(), project);
            } else {
                return Err(OptimError::InvalidConfig(format!(
                    "Project '{}' not found",
                    name
                )));
            }
        }

        Ok(self.projects.get_mut(name).expect("unwrap failed"))
    }

    /// Save a project to disk
    pub fn save_project(&self, name: &str) -> Result<()> {
        if let Some(project) = self.projects.get(name) {
            let project_file = self.storage_dir.join(format!("{}.json", name));
            let content = serde_json::to_string_pretty(project)?;
            std::fs::write(&project_file, content)?;
        }

        Ok(())
    }

    /// List all projects
    pub fn list_projects(&self) -> Vec<&str> {
        self.projects.keys().map(|s| s.as_str()).collect()
    }

    /// Delete a project
    pub fn delete_project(&mut self, name: &str) -> Result<()> {
        self.projects.remove(name);
        let project_file = self.storage_dir.join(format!("{}.json", name));
        if project_file.exists() {
            std::fs::remove_file(&project_file)?;
        }

        Ok(())
    }
}

impl Default for ManagerSettings {
    fn default() -> Self {
        Self {
            default_template: None,
            auto_save_frequency: 15, // 15 minutes
            enable_cloud_backup: false,
            cloud_provider: None,
            notifications: NotificationSettings::default(),
        }
    }
}

impl Default for NotificationSettings {
    fn default() -> Self {
        Self {
            email_enabled: true,
            slack_enabled: false,
            webhook_url: None,
            frequency: NotificationFrequency::Daily,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use tempfile::tempdir;

    #[test]
    fn test_research_project_creation() {
        let project = ResearchProject::new("Test Project")
            .description("A test research project")
            .research_area(ResearchArea::MachineLearning)
            .add_researcher("Dr. Test", "test@example.com")
            .enable_reproducibility(true);

        assert_eq!(project.name, "Test Project");
        assert_eq!(project.description, "A test research project");
        assert_eq!(project.research_area, ResearchArea::MachineLearning);
        assert_eq!(project.researchers.len(), 1);
        assert!(project.settings.enable_reproducibility);
    }

    #[test]
    fn test_project_manager() {
        let temp_dir = tempdir().expect("unwrap failed");
        let mut manager =
            ResearchProjectManager::new(temp_dir.path().to_path_buf()).expect("unwrap failed");

        let project = manager
            .create_project("Test Project")
            .expect("unwrap failed");
        project.description = "Test description".to_string();

        manager.save_project("Test Project").expect("unwrap failed");

        let projects = manager.list_projects();
        assert!(projects.contains(&"Test Project"));

        manager
            .delete_project("Test Project")
            .expect("unwrap failed");
        let projects = manager.list_projects();
        assert!(!projects.contains(&"Test Project"));
    }
}