Commit History

Update requirements.txt
d8e8692
verified

VIATEUR-AI commited on

Update requirements.txt
0e82dbf
verified

VIATEUR-AI commited on

python==3.11 qiskit==1.12.0 qiskit-nature==0.7.3 qiskit-algorithms==0.6.0 pyscf gradio==3.40.1 plotly==5.17.0
1ed693a
verified

VIATEUR-AI commited on

# ===== Ultimate Quantum Chemistry Platform (Starter) ===== # Python 3.11 + Qiskit stable + Gradio + Plotly import numpy as np import plotly.graph_objects as go import gradio as gr from qiskit_nature.second_q.drivers import PySCFDriver from qiskit_nature.second_q.problems import ElectronicStructureProblem from qiskit_nature.second_q.mappers import JordanWignerMapper from qiskit.algorithms.minimum_eigensolvers import VQE from qiskit.algorithms.optimizers import COBYLA from qiskit.circuit.library import TwoLocal from qiskit.primitives import Estimator # stable Qiskit 1.12 # ---------------------------- # Molecules Library # ---------------------------- molecules = { "H2": {"atoms": ["H", "H"], "coords": [(0,0,0), (0,0,0.74)]}, "LiH": {"atoms": ["Li", "H"], "coords": [(0,0,0), (0,0,1.6)]}, "BeH2": {"atoms": ["Be","H","H"], "coords": [(0,0,0), (0,0,1.3), (0,0,-1.3)]} } # ---------------------------- # Quantum ground state energy # ---------------------------- def compute_ground_state_energy(mol_name, bond_length): bond_length = float(bond_length) if mol_name == "H2": atom_str = f"H 0 0 0; H 0 0 {bond_length}" elif mol_name == "LiH": atom_str = f"Li 0 0 0; H 0 0 {bond_length}" elif mol_name == "BeH2": # symmetrically along z-axis atom_str = f"Be 0 0 0; H 0 0 {bond_length}; H 0 0 {-bond_length}" else: raise ValueError("Molecule not supported") driver = PySCFDriver(atom=atom_str, basis="sto3g") problem = ElectronicStructureProblem(driver) hamiltonian = problem.second_q_ops()[0] qubit_op = JordanWignerMapper().map(hamiltonian) ansatz = TwoLocal(qubit_op.num_qubits, "ry", "cz", reps=2) vqe = VQE(estimator=Estimator(), ansatz=ansatz, optimizer=COBYLA(maxiter=80)) result = vqe.compute_minimum_eigenvalue(qubit_op) energy = result.eigenvalue.real return energy # ---------------------------- # 3D molecule plot # ---------------------------- def molecule_3d_plot(mol_name, bond_length): bond_length = float(bond_length) if mol_name == "H2": coords = [(0,0,0),(0,0,bond_length)] elif mol_name == "LiH": coords = [(0,0,0),(0,0,bond_length)] elif mol_name == "BeH2": coords = [(0,0,0),(0,0,bond_length),(0,0,-bond_length)] else: coords = [] x, y, z = zip(*coords) fig = go.Figure() fig.add_trace(go.Scatter3d( x=x, y=y, z=z, mode="markers", marker=dict(size=8, color="red") )) fig.add_trace(go.Scatter3d( x=x, y=y, z=z, mode="lines", line=dict(color="blue", width=5) )) fig.update_layout(scene=dict(aspectmode="data")) return fig # ---------------------------- # Energy curve precompute (for 0.4 - 2.0 Γ…) # ---------------------------- bond_grid = np.linspace(0.4, 2.0, 12) energy_curves = {} for mol in molecules: energy_curves[mol] = [compute_ground_state_energy(mol, bl) for bl in bond_grid] # ---------------------------- # Update UI # ---------------------------- def update_ui(mol_name, bond_length): bond_length = float(bond_length) energy = compute_ground_state_energy(mol_name, bond_length) mol_fig = molecule_3d_plot(mol_name, bond_length) curve_fig = go.Figure() curve_fig.add_trace(go.Scatter( x=bond_grid, y=energy_curves[mol_name], mode="lines+markers", name="Energy Curve" )) curve_fig.add_trace(go.Scatter( x=[bond_length], y=[energy], mode="markers", marker=dict(size=12, color="green"), name="Current Energy" )) min_idx = int(np.argmin(energy_curves[mol_name])) curve_fig.add_trace(go.Scatter( x=[bond_grid[min_idx]], y=[energy_curves[mol_name][min_idx]], mode="markers", marker=dict(size=14, color="orange"), name="Equilibrium" )) curve_fig.update_layout( xaxis_title="Bond Length (Γ…)", yaxis_title="Energy (Hartree)" ) text = f"Ground state energy: {energy:.6f} Hartree\nEquilibrium bond length β‰ˆ {bond_grid[min_idx]:.2f} Γ…" return text, mol_fig, curve_fig # ---------------------------- # Gradio App # ---------------------------- with gr.Blocks() as demo: gr.Markdown("# 🧬 Ultimate Quantum Chemistry Platform") mol_dropdown = gr.Dropdown(list(molecules.keys()), value="H2", label="Select Molecule") bond_slider = gr.Slider(0.4, 2.0, value=0.74, step=0.01, label="Bond Length (Γ…)") energy_box = gr.Textbox(label="Energy", lines=2) mol_plot = gr.Plot(label="3D Molecule") curve_plot = gr.Plot(label="Energy Curve") mol_dropdown.change(update_ui, [mol_dropdown, bond_slider], [energy_box, mol_plot, curve_plot]) bond_slider.change(update_ui, [mol_dropdown, bond_slider], [energy_box, mol_plot, curve_plot]) demo.launch()
7c5acc4
verified

VIATEUR-AI commited on

python==3.11 qiskit==1.12.0 qiskit-nature==0.7.3 qiskit-algorithms==0.6.0 pyscf gradio plotly
96b3b62
verified

VIATEUR-AI commited on

# ===== app.py ===== # Full interactive H2 Quantum Simulator + 3D molecule (modern Qiskit) # --- Standard math --- import numpy as np # --- Graphing & UI --- import plotly.graph_objects as go import gradio as gr # --- Qiskit Nature (modern second_q API) --- from qiskit_nature.second_q.drivers import PySCFDriver from qiskit_nature.second_q.problems import ElectronicStructureProblem from qiskit_nature.second_q.mappers import JordanWignerMapper # --- Qiskit Algorithms (modern primitives API) --- from qiskit_algorithms.minimum_eigensolvers import VQE from qiskit_algorithms.optimizers import COBYLA from qiskit.circuit.library import TwoLocal from qiskit.primitives import Estimator # ---------------------------- # Compute H2 ground state energy using VQE # ---------------------------- def h2_ground_state_energy(bond_length): bond_length = float(bond_length) # Electronic structure driver driver = PySCFDriver( atom=f"H 0 0 0; H 0 0 {bond_length}", basis="sto3g" ) problem = ElectronicStructureProblem(driver) # Get second-quantized Hamiltonian second_q_ops = problem.second_q_ops() hamiltonian = second_q_ops[0] # Map fermions -> qubits mapper = JordanWignerMapper() qubit_op = mapper.map(hamiltonian) # Ansatz ansatz = TwoLocal( num_qubits=qubit_op.num_qubits, rotation_blocks="ry", entanglement_blocks="cz", reps=2 ) # Optimizer + estimator optimizer = COBYLA(maxiter=100) estimator = Estimator() # VQE vqe = VQE( estimator=estimator, ansatz=ansatz, optimizer=optimizer ) result = vqe.compute_minimum_eigenvalue(qubit_op) return result.eigenvalue.real # ---------------------------- # Create 3D molecule plot # ---------------------------- def h2_3d_plot(bond_length): bond_length = float(bond_length) x = [0, 0] y = [0, 0] z = [0, bond_length] fig = go.Figure() # Atoms fig.add_trace(go.Scatter3d( x=x, y=y, z=z, mode="markers", marker=dict(size=10, color="red"), name="Hydrogen atoms" )) # Bond fig.add_trace(go.Scatter3d( x=x, y=y, z=z, mode="lines", line=dict(color="blue", width=5), name="Bond" )) fig.update_layout( scene=dict( xaxis_title="X (Γ…)", yaxis_title="Y (Γ…)", zaxis_title="Z (Γ…)", aspectmode="data" ), margin=dict(l=0, r=0, b=0, t=0) ) return fig # ---------------------------- # Generate energy curve over bond lengths # ---------------------------- def h2_energy_curve(dummy): bond_lengths = np.linspace(0.4, 2.0, 10) energies = [h2_ground_state_energy(bl) for bl in bond_lengths] fig = go.Figure() fig.add_trace(go.Scatter( x=bond_lengths, y=energies, mode="lines+markers" )) fig.update_layout( title="Hβ‚‚ Ground State Energy vs Bond Length", xaxis_title="Bond Length (Γ…)", yaxis_title="Energy (Hartree)" ) return fig # ---------------------------- # Full interface: single bond length + 3D molecule # ---------------------------- def full_interface(bond_length): bond_length = float(bond_length) energy = h2_ground_state_energy(bond_length) mol_fig = h2_3d_plot(bond_length) return f"Ground state energy: {energy:.6f} Hartree", mol_fig # --- Gradio interfaces --- iface = gr.Interface( fn=full_interface, inputs=gr.Textbox( label="Bond Length (Γ…)", placeholder="Enter e.g. 0.74" ), outputs=[ gr.Textbox(label="Ground State Energy"), gr.Plot(label="3D Molecule") ], title="Hβ‚‚ Quantum Simulator", description="Interactive VQE simulation + 3D visualization of the Hβ‚‚ molecule." ) energy_curve_iface = gr.Interface( fn=h2_energy_curve, inputs=gr.Textbox(label="Dummy Input", placeholder="Press submit"), outputs=gr.Plot(label="Energy Curve"), title="Hβ‚‚ Energy Curve", description="Ground state energy of Hβ‚‚ for bond lengths 0.4–2.0 Γ…." ) demo = gr.TabbedInterface( [iface, energy_curve_iface], ["Single Bond Length", "Energy Curve"] ) # Launch app demo.launch()
8c55141
verified

VIATEUR-AI commited on

# ===== app.py ===== # Full interactive H2 Quantum Simulator + 3D molecule (modern Qiskit) # --- Standard math --- import numpy as np # --- Graphing & UI --- import plotly.graph_objects as go import gradio as gr # --- Qiskit (modern second_q API) --- from qiskit_nature.second_q.drivers import PySCFDriver from qiskit_nature.second_q.problems import ElectronicStructureProblem from qiskit_nature.second_q.converters import QubitConverter from qiskit_nature.second_q.mappers import JordanWignerMapper from qiskit.algorithms import VQE from qiskit.algorithms.optimizers import COBYLA from qiskit.circuit.library import TwoLocal from qiskit.utils import QuantumInstance from qiskit import Aer # ---------------------------- # Compute H2 ground state energy using VQE # ---------------------------- def h2_ground_state_energy(bond_length): bond_length = float(bond_length) driver = PySCFDriver(atom=f"H 0 0 0; H 0 0 {bond_length}", basis='sto3g') problem = ElectronicStructureProblem(driver) # Hamiltonian second_q_ops = problem.second_q_ops() main_op = second_q_ops[0] # Map to qubits qubit_converter = QubitConverter(mapper=JordanWignerMapper()) qubit_op = qubit_converter.convert(main_op) # Ansatz & optimizer ansatz = TwoLocal(qubit_op.num_qubits, 'ry', 'cz', reps=2) optimizer = COBYLA(maxiter=100) # Quantum instance backend = Aer.get_backend('statevector_simulator') qi = QuantumInstance(backend) # Run VQE vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=qi) result = vqe.compute_minimum_eigenvalue(qubit_op) energy = result.eigenvalue.real return energy # ---------------------------- # Create 3D molecule plot # ---------------------------- def h2_3d_plot(bond_length): bond_length = float(bond_length) x = [0, 0] y = [0, 0] z = [0, bond_length] fig = go.Figure() # Atoms fig.add_trace(go.Scatter3d( x=x, y=y, z=z, mode='markers', marker=dict(size=10, color='red') )) # Bond fig.add_trace(go.Scatter3d( x=x, y=y, z=z, mode='lines', line=dict(color='blue', width=5) )) fig.update_layout(scene=dict( xaxis_title='X Γ…', yaxis_title='Y Γ…', zaxis_title='Z Γ…', aspectmode='data' )) return fig # ---------------------------- # Generate energy curve over bond lengths # ---------------------------- def h2_energy_curve(dummy): bond_lengths = np.linspace(0.4, 2.0, 10) energies = [h2_ground_state_energy(bl) for bl in bond_lengths] fig = go.Figure() fig.add_trace(go.Scatter( x=bond_lengths, y=energies, mode='lines+markers' )) fig.update_layout( title="H2 Ground State Energy vs Bond Length", xaxis_title="Bond Length (Γ…)", yaxis_title="Energy (Hartree)" ) return fig # ---------------------------- # Full interface: single bond length + 3D molecule # ---------------------------- def full_interface(bond_length): bond_length_float = float(bond_length) energy = h2_ground_state_energy(bond_length_float) mol_fig = h2_3d_plot(bond_length_float) return f"Ground state energy: {energy:.6f} Hartree", mol_fig # --- Gradio interfaces --- iface = gr.Interface( fn=full_interface, inputs=gr.Textbox(label="Bond Length Γ…", placeholder="Enter e.g., 0.74"), outputs=[gr.Textbox(label="Ground State Energy"), gr.Plot(label="3D Molecule")], title="H2 Quantum Simulator", description="Interactive 3D molecule + VQE simulation of H2. Enter bond length to compute energy." ) energy_curve_iface = gr.Interface( fn=h2_energy_curve, inputs=gr.Textbox(label="Dummy Input", placeholder="Press submit"), outputs=gr.Plot(label="Energy Curve"), title="H2 Energy Curve", description="Shows ground state energy of H2 over bond lengths 0.4–2.0 Γ…." ) demo = gr.TabbedInterface( [iface, energy_curve_iface], ["Single Bond Length", "Energy Curve"] ) # Launch app demo.launch()
e983e5c
verified

VIATEUR-AI commited on

Update requirements.txt
e2a35b3
verified

VIATEUR-AI commited on

Update requirements.txt
222a780
verified

VIATEUR-AI commited on

Update requirements.txt
6642d51
verified

VIATEUR-AI commited on

Update requirements.txt
787dd7a
verified

VIATEUR-AI commited on

Update requirements.txt
f3ed760
verified

VIATEUR-AI commited on

Update requirements.txt
f4f38ab
verified

VIATEUR-AI commited on

gradio plotly qiskit qiskit-nature matplotlib numpy
99de633
verified

VIATEUR-AI commited on

Update requirements.txt
add40e9
verified

VIATEUR-AI commited on

# app.py # Full interactive H2 Quantum Simulator + 3D molecule # Install dependencies: gradio, plotly, qiskit, qiskit-nature, matplotlib import numpy as np import plotly.graph_objects as go import gradio as gr # Qiskit imports from qiskit_nature.drivers import PySCFDriver from qiskit_nature.problems.second_quantization.electronic import ElectronicStructureProblem from qiskit_nature.converters.second_quantization import QubitConverter from qiskit_nature.mappers.second_quantization import JordanWignerMapper from qiskit.algorithms import VQE from qiskit.algorithms.optimizers import COBYLA from qiskit.circuit.library import TwoLocal from qiskit.utils import QuantumInstance from qiskit import Aer # ----- Function to compute ground state energy of H2 using VQE ----- def h2_ground_state_energy(bond_length): bond_length = float(bond_length) # Define H2 molecule driver = PySCFDriver(atom=f"H 0 0 0; H 0 0 {bond_length}", basis='sto3g') problem = ElectronicStructureProblem(driver) # Hamiltonian second_q_ops = problem.second_q_ops() main_op = second_q_ops[0] # Map to qubits qubit_converter = QubitConverter(mapper=JordanWignerMapper()) qubit_op = qubit_converter.convert(main_op) # Ansatz & optimizer ansatz = TwoLocal(qubit_op.num_qubits, 'ry', 'cz', reps=2) optimizer = COBYLA(maxiter=100) # Quantum instance backend = Aer.get_backend('statevector_simulator') qi = QuantumInstance(backend) # Run VQE vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=qi) result = vqe.compute_minimum_eigenvalue(qubit_op) energy = result.eigenvalue.real return energy # ----- Function to create 3D molecule plot using plotly ----- def h2_3d_plot(bond_length): bond_length = float(bond_length) x = [0, 0] y = [0, 0] z = [0, bond_length] fig = go.Figure() # Atoms fig.add_trace(go.Scatter3d(x=x, y=y, z=z, mode='markers', marker=dict(size=10, color='red'))) # Bond fig.add_trace(go.Scatter3d(x=x, y=y, z=z, mode='lines', line=dict(color='blue', width=5))) fig.update_layout(scene=dict( xaxis_title='X Γ…', yaxis_title='Y Γ…', zaxis_title='Z Γ…', aspectmode='data' )) return fig # ----- Function to generate energy curve over range of bond lengths ----- def h2_energy_curve(dummy): bond_lengths = np.linspace(0.4, 2.0, 10) energies = [] for bl in bond_lengths: energy = h2_ground_state_energy(bl) energies.append(energy) fig = go.Figure() fig.add_trace(go.Scatter(x=bond_lengths, y=energies, mode='lines+markers')) fig.update_layout( title="H2 Ground State Energy vs Bond Length", xaxis_title="Bond Length (Γ…)", yaxis_title="Energy (Hartree)" ) return fig # ----- Combine all into one interface ----- def full_interface(bond_length): bond_length_float = float(bond_length) energy = h2_ground_state_energy(bond_length_float) mol_fig = h2_3d_plot(bond_length_float) return f"Ground state energy: {energy:.6f} Hartree", mol_fig iface = gr.Interface( fn=full_interface, inputs=gr.Textbox(label="Bond Length Γ…", placeholder="Enter e.g., 0.74"), outputs=[gr.Textbox(label="Ground State Energy"), gr.Plot(label="3D Molecule")], title="H2 Quantum Simulator", description="Interactive 3D molecule + VQE Quantum simulation of H2. Enter bond length to compute energy and see molecule." ) # Add separate energy curve tab energy_curve_iface = gr.Interface( fn=h2_energy_curve, inputs=gr.Textbox(label="Dummy Input", placeholder="Press submit"), outputs=gr.Plot(label="Energy Curve"), title="H2 Energy Curve", description="Shows ground state energy of H2 over bond lengths 0.4–2.0 Γ…." ) # Launch all interfaces as Tabs demo = gr.TabbedInterface([iface, energy_curve_iface], ["Single Bond Length", "Energy Curve"]) demo.launch(share=True)
c9c6353
verified

VIATEUR-AI commited on

Update app.py
087fadd
verified

VIATEUR-AI commited on

Update requirements.txt
34d6f67
verified

VIATEUR-AI commited on

Create requirements.txt
8730684
verified

VIATEUR-AI commited on

Update app.py
448d79c
verified

VIATEUR-AI commited on

Rename app. py to app.py
d876107
verified

VIATEUR-AI commited on

Create app. py
8a69240
verified

VIATEUR-AI commited on

initial commit
58cd721
verified

VIATEUR-AI commited on