Skip to main content

Soft Algebra Optimizer for Quantum & Complex Optimization

Project description

Mobiu-Q

Mobiu-Q is a next-generation optimizer built on Soft Algebra and Demeasurement theory, enabling stable and efficient optimization in quantum variational algorithms (VQE, QAOA).

✨ Features

  • Soft Algebra update rule for stable convergence
  • SPSA Demeasurement for noisy hardware
  • Adaptive "Noisy Mode" presets
  • Validated on real quantum hardware (IBM)

📦 Installation

pip install mobiu-q

🔑 License

from mobiu_q import activate_license

activate_license("YOUR-LICENSE-KEY")
  • Free tier: 5 runs/month
  • Pro tier: Unlimited runs

🚀 Quick Start (Simulation)

Best for clean simulations or statevector backends.

import numpy as np
from mobiu_q import MobiuQCore, Demeasurement, get_energy_function

energy_fn = get_energy_function("h2_molecule")

# Initialize in standard mode
opt = MobiuQCore(mode="standard") 

params = np.random.uniform(-np.pi, np.pi, 6)

for step in range(50):
    E = energy_fn(params)
    grad = Demeasurement.finite_difference(energy_fn, params)
    params = opt.step(params, grad, E)

opt.end()  # End session

⚡ Real Hardware / Shot Noise

When running on noisy quantum computers (IBM, IonQ) or simulators with shot noise:

# Initialize in noisy mode (robust learning)
opt = MobiuQCore(mode="noisy") 

for step in range(100):
    # SPSA returns gradient AND energy estimate (saves 50% measurements)
    grad, E = Demeasurement.spsa(energy_fn, params, c_shift=0.1)
    params = opt.step(params, grad, E)

opt.end()

🔄 Multi-Seed Experiments (Important!)

When running experiments with multiple seeds, use new_run() to reset the optimizer state between seeds without consuming additional runs from your quota.

✅ Correct Usage (counts as 1 run)

from mobiu_q import MobiuQCore, Demeasurement

opt = MobiuQCore(mode="standard")

for seed in range(10):
    np.random.seed(seed)
    params = np.random.uniform(-np.pi, np.pi, n_params)
    
    opt.new_run()  # Reset optimizer state, keep session open
    
    for step in range(100):
        grad = Demeasurement.finite_difference(energy_fn, params)
        params = opt.step(params, grad, energy_fn(params))

opt.end()  # Only here it counts as 1 run!

❌ Wrong Usage (counts as 10 runs!)

# DON'T do this - each iteration creates a new session
for seed in range(10):
    opt = MobiuQCore(mode="standard")  # New session each time!
    # ... optimization ...
    opt.end()  # Counted as a run

💡 Comparing Multiple Optimizers

# Create all optimizers once, before the seed loop
opt_standard = MobiuQCore(mode="standard")
opt_noisy = MobiuQCore(mode="noisy")

for seed in range(20):
    np.random.seed(seed)
    init_params = np.random.uniform(-np.pi, np.pi, n_params)
    
    # Test standard mode
    opt_standard.new_run()
    params = init_params.copy()
    for step in range(100):
        grad = Demeasurement.finite_difference(energy_fn, params)
        params = opt_standard.step(params, grad, energy_fn(params))
    
    # Test noisy mode
    opt_noisy.new_run()
    params = init_params.copy()
    for step in range(100):
        grad, E = Demeasurement.spsa(energy_fn, params)
        params = opt_noisy.step(params, grad, E)

# End all sessions (counts as 2 runs total)
opt_standard.end()
opt_noisy.end()

📊 Performance Results

Clean Simulation

Tested on H2 molecule (6 params), 100 seeds:

Optimizer Gap to Ground State Improvement
Adam 0.089 -
Mobiu-Q 0.034 +62%

Shot Noise Simulation

Tested on Transverse Ising (4 qubits), 30 seeds:

Shots Adam Gap Mobiu-Q Gap Improvement p-value
1000 1.63 1.48 +9.2% 0.002 ✅
500 1.65 1.49 +9.8% 0.002 ✅
50 2.00 1.82 +9.2% 0.009 ✅

Real Quantum Hardware (IBM Fez)

H2 molecule optimization:

Metric Result
Initial gap 0.22
Final gap 0.034
Improvement 85%

💡 Choosing the Right Mode

Scenario Mode Gradient Method
Clean simulation (statevector) standard finite_difference
Shot noise simulation noisy spsa
Real quantum hardware noisy spsa

Mode Settings

Mode Learning Rate Best For
standard 0.05 Simulators (Qiskit Aer, PennyLane, Cirq)
noisy 0.02 Real hardware (IBM, IonQ, Rigetti)

📚 Built-in Problems

from mobiu_q import list_problems, get_energy_function, get_ground_state_energy

print(list_problems())
# ['h2_molecule', 'lih_molecule', 'transverse_ising', 'heisenberg_xxz', ...]

energy_fn = get_energy_function("h2_molecule")
E0 = get_ground_state_energy("h2_molecule")

⚙️ API Reference

MobiuQCore

MobiuQCore(
    license_key=None,       # Your license key (or use activate_license())
    mode="standard",        # 'standard' or 'noisy'
    base_lr=None,           # Custom learning rate (overrides mode)
    verbose=True            # Print session messages
)

Methods:

  • step(params, gradient, energy) → updated params
  • new_run() → reset optimizer state for new seed (same session)
  • end() → close session (counts as 1 run)

Demeasurement

# For clean simulations (2*N function calls)
grad = Demeasurement.finite_difference(fn, params)

# For noisy environments (only 2 function calls!)
grad, energy = Demeasurement.spsa(fn, params, c_shift=0.1)

🔥 Full Example: IBM Hardware

from qiskit_ibm_runtime import QiskitRuntimeService, EstimatorV2
from mobiu_q import MobiuQCore, Demeasurement

service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.least_busy(simulator=False, min_num_qubits=5)
estimator = EstimatorV2(mode=backend)

opt = MobiuQCore(mode="noisy")

for step in range(60):
    grad, energy = Demeasurement.spsa(
        lambda p: estimator.run([(circuit, observable)]).result()[0].data.evs.item(),
        params,
        c_shift=0.12
    )
    params = opt.step(params, grad, energy)

opt.end()

© Mobiu Technologies, 2025

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mobiu_q-1.0.6.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mobiu_q-1.0.6-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file mobiu_q-1.0.6.tar.gz.

File metadata

  • Download URL: mobiu_q-1.0.6.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for mobiu_q-1.0.6.tar.gz
Algorithm Hash digest
SHA256 b6ba44b20acf348ac7478fa4b7e1deb2182c94a7f66df5eb94bbd617a49ccab4
MD5 54b11fbc05c540050a4cd975b68331e8
BLAKE2b-256 fbcdfd171a1cd40a93cc814d76067a6622de25fd029d5cfaca7a358398e496b0

See more details on using hashes here.

File details

Details for the file mobiu_q-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: mobiu_q-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for mobiu_q-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 33f3d21d9407fc2a94d3b66172cc1cc76a8daf04169fd43f4bc7126018bea375
MD5 b705838e689472380a6f56a5253dfaad
BLAKE2b-256 43b98eb461a25766729274f00202d6e7ae48460173d5b4169e72f3b6256c949e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page