There is a problem in my code that i can not solve. Python ABM, Mesa, Pandas

This my code:

import random
from mesa import Agent, Model
from mesa.space import MultiGrid
import math
import pandas as pd
import matplotlib.pyplot as plt

class MyAgent(Agent):
  def __init__(self, unique_id, model, pos, opinion, stubborn=False):
    super().__init__(unique_id, model)
    self.pos = pos
    self.opinion = opinion
    self.stubborn = stubborn
    self.neighbors = []

class MyModel(Model):
  def __init__(self):
    self.schedule = None
    self.grid = None

def create_population(num_agents, stubborn_ratio=0.1):
  model = MyModel()
  agents = []

  for i in range(num_agents):
    opinion = random.choice(["conservative", "liberal", "neutral"])
    is_stubborn = random.random() < stubborn_ratio
    agents.append(MyAgent(unique_id=i, model=model, pos=None, opinion=opinion, stubborn=is_stubborn))
  return agents

def assign_neighbors(agents, grid_width = None, grid_height = None):
  # Here, we are choosing the width and height of our matrix. if user 
  # already choose, use it. If not, assign it acc to agent num.
  if not grid_width or not grid_height:
    grid_width = int(math.ceil(math.sqrt(len(agents))))
    grid_height = grid_width
  # create the matrix. "grid" will be 2D matrix.
  grid = MultiGrid(width=grid_width,height=grid_height, torus=True)
  
  for agent in agents:
    x = random.randint(0, grid_width - 1)
    y = random.randint(0, grid_height - 1)
    agent.pos = (x, y)
    grid.place_agent(agent, (x, y)) #place agents on the grid.
    
  for agent in agents:
    x,y = agent.pos
    agent.neighbors = grid.get_neighbors((x,y), moore=True, include_center=False)
  return grid

def visualise_agents(agents):
  data = []

  for agent in agents:
    color = "gray"
    if agent.opinion == "conservative":
      color = "red"
    elif agent.opinion == "liberal":
      color = "blue"
    
    data.append({"x": agent.pos[0], "y": agent.pos[1], "opinion": agent.opinion, "color": color})
  
    df = pd.DataFrame(data)
  
    plt.figure(figsize=(8,8))
    scatter = plt.scatter(df["x"], df["y"], c=df["color"], label=df["opinion"],alpha=0.7)
  
    red_patch = plt.Line2D([0], [0], marker="o", color="w", markerfacecolor="red", markersize=10, label = "Conservative")
    blue_patch = plt.Line2D([0], [0], marker="o", color="w", markerfacecolor="blue", markersize=10, label = "Liberal")
    gray_patch = plt.Line2D([0], [0], marker="o", color="w", markerfacecolor="gray", markersize=10, label = "Neutral")
    plt.legend(handles=[red_patch, blue_patch, gray_patch])
  
    plt.title("Agent positions and Ideologies")
    plt.xlabel("X position")
    plt.ylabel("Y position")
    plt.grid(True)
    plt.show()

agents = create_population(100)
assign_neighbors(agents)

visualise_agents(agents)

and this is the error:

Traceback (most recent call last):
  File "c:Users...project.py", line 79, in <module>
    agents = create_population(100)
^^^^^^^^^^^^^^^^^^^^^^
  File "c:Users...project.py", line 28, in create_population
    agents.append(MyAgent(unique_id=i, model=model, pos=None, opinion=opinion, stubborn=is_stubborn))
^^^^^^^^^^^^^
  File "c:Users...project.py", line 10, in __init__
    super().__init__(unique_id, model)
  File "C:Users...AppDataLocalProgramsPythonPython312Libsite-packagesmesaagent.py", line 64, in __init__       
    super().__init__(*args, **kwargs)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)

I have been trying to fix this issue for a while. Basically i am just learning python, and now i am trying to build ABM with mesa. Because i couldn’t find detailed tutorials in youtube i am moving with AI but it also couldn’t help me with this. I am trying to simulate political ideology changes of people. Before i continue and detail the whole code deeply, i wanted to see what i have done but now it is not working.

New contributor

Abdurrahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật