Skip to content

Instantly share code, notes, and snippets.

@Vasuji
Created May 31, 2024 23:20
Show Gist options
  • Save Vasuji/59f3256dc62b2530d84f3ab66498ee23 to your computer and use it in GitHub Desktop.
Save Vasuji/59f3256dc62b2530d84f3ab66498ee23 to your computer and use it in GitHub Desktop.
Statistical Mechanics modeling with multi-agent Ai
import os
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool
# Define tools
search_tool = SerperDevTool()
# Define agents
theory_agent = Agent(
role='Theory Agent',
goal='Explore the theory and mathematical equations for simulating the Ising model in 2D',
verbose=True,
memory=True,
backstory="You are an expert in theoretical physics with a focus on statistical mechanics.",
tools=[search_tool],
allow_delegation=True
)
simulation_agent = Agent(
role='Simulation Agent',
goal='Build the code for simulating the Ising model in 2D using Python',
verbose=True,
memory=True,
backstory="You are a skilled programmer with experience in scientific computing.",
allow_delegation=False
)
result_agent = Agent(
role='Result Agent',
goal='Extract statistical properties of the system through measurement and visualization',
verbose=True,
memory=True,
backstory="You are a data scientist specializing in statistical analysis and visualization.",
tools=[search_tool],
allow_delegation=False
)
# Define tasks
theory_task = Task(
description=(
"Explore the theory and mathematical equations for simulating the Ising model in 2D. "
"Your final report should include an explanation of the Ising model, its Hamiltonian, "
"and the Monte Carlo method for simulating the system."
),
expected_output='A comprehensive report on the theory of the Ising model in 2D.',
tools=[search_tool],
agent=theory_agent,
)
simulation_task = Task(
description=(
"Build the code for simulating the Ising model in 2D using Python. Ensure the code includes "
"initializing the lattice, updating spins using the Metropolis algorithm, and running the simulation for a sufficient number of steps."
),
expected_output='A Python script that simulates the Ising model in 2D.',
agent=simulation_agent,
)
result_task = Task(
description=(
"Extract the statistical properties of the system through measurement and visualization. "
"Your report should include measurements of magnetization, energy, and heat capacity, along with corresponding plots."
),
expected_output='A report and plots showing the statistical properties of the Ising model in 2D.',
tools=[search_tool],
agent=result_agent,
)
# Create and kick off the crew
crew = Crew(
agents=[theory_agent, simulation_agent, result_agent],
tasks=[theory_task, simulation_task, result_task],
process=Process.sequential
)
result = crew.kickoff()
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment