CoolFace
Apppublic

TheGreatUnknown/Qutrit_Quantum_System_Simulator

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
app.py53 linesDownload Raw Back to root
1import gradio as gr2import numpy as np3import plotly.graph_objects as go4 5# Define the simulation function6def run_simulation(num_qutrits, noise_type, gamma, t_max, num_steps):7    # Simulated quantum evolution data (simplified for demo)8    times = np.linspace(0, t_max, num_steps)9    results = {10        "negativity": np.exp(-gamma * times) * np.sin(times) ** 2,11        "purity": 0.5 + 0.5 * np.exp(-2 * gamma * times),12        "entropy": -np.log(0.5 + 0.5 * np.exp(-2 * gamma * times)),13        "concurrence": np.exp(-gamma * times) * np.cos(times) ** 214    }15    return results16 17# Define the Gradio interface18demo = gr.Blocks()19 20with demo:21    gr.Markdown("# Qutrit Quantum System Simulator")22    23    with gr.Row():24        num_qutrits = gr.Radio(["1", "2"], value="2", label="Number of Qutrits")25        noise_type = gr.Radio(["Amplitude Damping", "Phase Damping", "Depolarizing"], value="Amplitude Damping", label="Noise Type")26        gamma = gr.Slider(0, 1, value=0.1, step=0.01, label="Noise Strength (γ)")27        t_max = gr.Slider(1, 100, value=10, step=1, label="Maximum Evolution Time")28        num_steps = gr.Slider(10, 1000, value=100, step=10, label="Number of Time Steps")29    30    with gr.Row():31        run_button = gr.Button("Run Simulation")32    33    with gr.Row():34        negativity_plot = gr.Plot(label="Negativity vs Time")35        purity_plot = gr.Plot(label="Purity vs Time")36        entropy_plot = gr.Plot(label="Rényi Entropy vs Time")37        concurrence_plot = gr.Plot(label="Concurrence Analog vs Time")38    39    # Define the simulation and plotting logic40    def simulate_and_plot(num_qutrits, noise_type, gamma, t_max, num_steps):41        results = run_simulation(num_qutrits, noise_type, gamma, t_max, num_steps)42        times = np.linspace(0, t_max, num_steps)43        44        negativity_plot.update(go.Figure(data=[go.Scatter(x=times, y=results["negativity"])]))45        purity_plot.update(go.Figure(data=[go.Scatter(x=times, y=results["purity"])]))46        entropy_plot.update(go.Figure(data=[go.Scatter(x=times, y=results["entropy"])]))47        concurrence_plot.update(go.Figure(data=[go.Scatter(x=times, y=results["concurrence"])]))48    49    # Link the button to the simulation and plotting logic50    run_button.click(simulate_and_plot, inputs=[num_qutrits, noise_type, gamma, t_max, num_steps])51 52# Launch the Gradio app53demo.launch()