# sir_model.pyimportargparseimportosimportjsonimportmatplotlib.pyplotaspltdefsir_model(N,beta,gamma,days,initial_infected=1):S=N-initial_infectedI=initial_infectedR=0S_history=[S]I_history=[I]R_history=[R]fordayinrange(days):new_infections=beta*S*I/Nnew_recoveries=gamma*IS-=new_infectionsI+=new_infections-new_recoveriesR+=new_recoveriesS_history.append(S)I_history.append(I)R_history.append(R)results={"S":S_history,"I":I_history,"R":R_history,"final_infected_total":R,"peak_infected":max(I_history),"peak_day":I_history.index(max(I_history))}withopen("output.json","w")asf:json.dump(results,f,indent=2)plt.figure(figsize=(10,6))plt.plot(S_history,label="Susceptible",color="blue")plt.plot(I_history,label="Infected",color="red")plt.plot(R_history,label="Recovered",color="green")plt.xlabel("Days")plt.ylabel("Number of Individuals")plt.title(f"SIR Model: β={beta:.3f}, γ={gamma:.3f}")plt.legend()plt.grid(True)plt.savefig("sir_curve.png",dpi=150)plt.close()print(f"Simulation complete: Peak infected = {max(I_history):.0f} on day {I_history.index(max(I_history))}")returnresultsif__name__=="__main__":parser=argparse.ArgumentParser(description="Run model with config file")parser.add_argument("--config",type=str,default="config.json")args=parser.parse_args()ifos.path.exists(args.config):withopen(args.config)asf:config=json.load(f)else:config={"N":10000,"beta":0.5,"gamma":0.1,"days":160}sir_model(**config)
Step 2: Create the experiment script — run_python_sir.py
# run_python_sir.pyfromidmtools.core.platform_factoryimportPlatformfromidmtools.entities.experimentimportExperimentfromidmtools_models.python.python_taskimportPythonTask# Use Container platform for local executionplatform=Platform("Container",job_directory="DEST")task=PythonTask(script_path="sir_model.py",python_path="python")# Set model parameterstask.parameters={"N":10000,"beta":0.5,"gamma":0.1,"days":160}# Create and run experimentexperiment=Experiment.from_task(task,name="SIR Python Model - Single Run")experiment.run(platform=platform,wait_until_done=True)print(f"Experiment ID: {experiment.id}")print(f"Status: {experiment.status}")