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

Implement comprehensive social simulation framework with CLI and input visualization #39

Merged
merged 4 commits into from
Nov 9, 2024

Conversation

leonvanbokhorst
Copy link
Owner

@leonvanbokhorst leonvanbokhorst commented Nov 9, 2024

  • Remove redundant validation in PersonalityTraits class
  • Update InputVisualizer to include all personality traits
  • Use model_dump() instead of dict() for consistent serialization
  • Add missing dominance and social_influence to trait visualization

The double 'dominance' error was occurring due to validation happening in multiple places. This commit simplifies the validation chain by:

  1. Relying on Pydantic's built-in Field validation
  2. Using model_dump() consistently for serialization
  3. Including all personality traits in visualizations
  4. Removing redundant validation checks

Key changes:

  • friction_flow/inputs/agent_inputs.py (lines 12-38): Simplified PersonalityTraits class
  • friction_flow/utils/input_visualizer.py (lines 77-100): Updated trait visualization

Summary by Sourcery

Implement a comprehensive social simulation framework with a CLI for managing simulations, input generation, and result analysis. Enhance input visualization to include all personality traits.

New Features:

  • Introduce a CLI for running social simulations, including commands for running simulations, generating configurations, analyzing results, and visualizing inputs.
  • Add support for generating random simulation inputs with realistic distributions of personality traits and social roles.
  • Implement a results manager to handle the logging and analysis of simulation metrics and events.

Enhancements:

  • Update the InputVisualizer to include all personality traits in visualizations, ensuring comprehensive trait representation.

…onality influence

- Refactor EmotionalDecisionMaking class to better incorporate personality traits
- Add detailed emotional reaction calculation based on personality factors
- Implement status threat evaluation for emotional responses
- Enhance deliberation process with weighted contributions and relationship context
- Add comprehensive emotional impact assessment and support needs identification
- Improve contribution gathering with personality-aware prompt modification
- Add relationship context tracking for better group dynamics modeling
- Add simulation coordinator and core agent components
- Implement group dynamics and emotional processing
- Add configuration management and CLI interface
- Create proposal and deliberation system
- Add event logging and analysis capabilities
- Set up project structure and dependencies

BREAKING CHANGE: Initial framework implementation
- Remove redundant validation in PersonalityTraits class
- Update InputVisualizer to include all personality traits
- Use model_dump() instead of dict() for consistent serialization
- Add missing dominance and social_influence to trait visualization

The double 'dominance' error was occurring due to validation happening in multiple places. This commit simplifies the validation chain by:

1. Relying on Pydantic's built-in Field validation
2. Using model_dump() consistently for serialization
3. Including all personality traits in visualizations
4. Removing redundant validation checks

Key changes:
- friction_flow/inputs/agent_inputs.py (lines 12-38): Simplified PersonalityTraits class
- friction_flow/utils/input_visualizer.py (lines 77-100): Updated trait visualization
Copy link
Contributor

sourcery-ai bot commented Nov 9, 2024

Reviewer's Guide by Sourcery

This pull request enhances the emotional and social dynamics simulation framework by implementing a comprehensive set of classes and utilities. The changes focus on improving personality trait handling, visualization capabilities, and emotional state management through consistent serialization and validation approaches.

Sequence diagram for agent emotional response calculation

sequenceDiagram
    participant Agent as EnhancedSocialAgent
    participant Proposal as DecisionProposal
    participant Dynamics as esh_status_dynamics
    Agent->>Dynamics: _calculate_initial_reaction(Proposal)
    alt stability < 0.5
        Dynamics->>Agent: ANXIOUS reaction
    end
    alt openness > 0.7
        Dynamics->>Agent: CONFIDENT reaction
    end
    alt dominance > 0.7
        Dynamics->>Agent: DEFENSIVE reaction
    end
    Dynamics->>Agent: Return reactions
Loading

Updated class diagram for PersonalityTraits and InputVisualizer

classDiagram
    class PersonalityTraits {
        - agreeableness: float
        - conscientiousness: float
        - dominance: float
        - extraversion: float
        - neuroticism: float
        - openness: float
        - social_influence: float
        + validate_traits(): void
    }
    class InputVisualizer {
        + visualize_traits(traits: PersonalityTraits): void
        + generate_visualizations(output_dir: Path): void
    }
    PersonalityTraits -- InputVisualizer : uses
Loading

Class diagram for EnhancedSocialAgent and GroupManager

classDiagram
    class EnhancedSocialAgent {
        - id: str
        - personality: PersonalityTraits
        - emotional_state: EmotionalState
        - status: Status
        + get_dominant_emotion(): EmotionalState.Emotion
    }
    class GroupManager {
        - agents: List~EnhancedSocialAgent~
        - groups: Dict~str, Group~
        + update_groups(): void
        + _calculate_similarity_matrix(): np.ndarray
    }
    EnhancedSocialAgent -- GroupManager : manages
    class Group {
        - id: str
        - members: Set~EnhancedSocialAgent~
        - cohesion: float
        - emotional_alignment: float
    }
    GroupManager o-- Group : contains
Loading

File-Level Changes

Change Details Files
Enhanced personality trait handling and validation in the agent input system
  • Simplified PersonalityTraits class with consistent field validation
  • Added model_dump() method for standardized serialization
  • Implemented field validators for personality traits
  • Added validation for personality trait ranges
friction_flow/inputs/agent_inputs.py
Implemented comprehensive simulation management and coordination system
  • Created SimulationCoordinator class for managing simulation lifecycle
  • Added event notification system for simulation steps
  • Implemented results management and metrics tracking
  • Added configuration validation and management
friction_flow/core/simulation_coordinator.py
friction_flow/config/simulation_config.py
Added visualization and input management capabilities
  • Created InputVisualizer class for generating network graphs
  • Added personality trait distribution visualization
  • Implemented role distribution visualization
  • Added input validation and loading utilities
friction_flow/utils/input_visualizer.py
friction_flow/inputs/input_manager.py
Implemented emotional dynamics and group behavior systems
  • Created EmotionalState class for managing agent emotions
  • Added GroupDeliberation system for group decision making
  • Implemented emotional influence calculations
  • Added support for emotional subgroups
friction_flow/emotions/emotional_state.py
friction_flow/emotions/emotional_dynamics.py
friction_flow/deliberation/deliberation_system.py
friction_flow/group/group_manager.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@leonvanbokhorst leonvanbokhorst changed the title Group-dynamics @sourcery-ai Nov 9, 2024
@leonvanbokhorst leonvanbokhorst self-assigned this Nov 9, 2024
@leonvanbokhorst leonvanbokhorst added the enhancement New feature or request label Nov 9, 2024
@sourcery-ai sourcery-ai bot changed the title @sourcery-ai Implement comprehensive social simulation framework with CLI and input visualization Nov 9, 2024
@leonvanbokhorst leonvanbokhorst added this to the Phase 1 milestone Nov 9, 2024
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @leonvanbokhorst - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding performance instrumentation to track memory usage and processing time of key simulation components
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/esh_status_dynamics.py Show resolved Hide resolved
try:
with open(filename, 'w') as f:
json.dump(self.events, f, indent=2)
self.events = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Event data could be lost if write fails

Only clear events after successful write to prevent data loss. Consider implementing a retry mechanism.

src/esh_status_dynamics.py Show resolved Hide resolved
"""Analyze simulation results"""
console = Console()

try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Explicitly raise from a previous error (raise-from-previous-error)

Comment on lines +1689 to +1691
valid_responses = [r for r in responses if r]
if not valid_responses:
return f"Agent {agent.id} is considering the matter."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): We've found these issues:

src/esh_status_dynamics.py Show resolved Hide resolved
src/esh_status_dynamics.py Show resolved Hide resolved
src/esh_status_dynamics.py Show resolved Hide resolved
src/esh_status_dynamics.py Show resolved Hide resolved
@leonvanbokhorst leonvanbokhorst merged commit 87c80d7 into main Nov 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant