API Reference

Core Engines

Qubit Engine: Wrapper around scqubits for qubit physics modeling.

class qforge.core.qubit_engine.QubitEngine[source]

Bases: object

Engine for qubit modeling and physics calculations using scqubits.

compute_spectrum(qubit, n_levels: int = 5, subtract_ground: bool = False) ndarray[source]

Compute energy spectrum of the qubit.

Parameters:
  • qubit – scqubits qubit object

  • n_levels – Number of energy levels to compute

  • subtract_ground – Whether to subtract ground state energy (setting E0 = 0)

Returns:

Array of energy eigenvalues

create_qubit(qubit_type: str, name: str, params: Dict[str, Any])[source]

Create a qubit instance.

Parameters:
  • qubit_type – Type of qubit (transmon, fluxonium, flux, zeropi)

  • name – Name for the qubit

  • params – Qubit parameters

Returns:

scqubits qubit object

delete_qubit(name: str)[source]

Delete a qubit by name.

Parameters:

name – Name of the qubit to delete

estimate_coherence(qubit, temperature: float = 0.015) Dict[str, Dict][source]

Estimate coherence times for the qubit.

Parameters:
  • qubit – scqubits qubit object

  • temperature – Bath temperature in Kelvin

Returns:

Dictionary with coherence time estimates

export_to_qiskit(qubit, output_path: str)[source]

Export qubit parameters for Qiskit noise modeling.

Parameters:
  • qubit – scqubits qubit object

  • output_path – Path to save parameters

export_to_qutip(qubit, output_path: str)[source]

Export qubit Hamiltonian to QuTiP format.

Parameters:
  • qubit – scqubits qubit object

  • output_path – Path to save the Hamiltonian

get_qubit(name: str)[source]

Get a qubit by name.

list_qubits() List[Dict][source]

List all created qubits with their properties.

load_qubit(input_path: str) Any[source]

Load qubit from JSON file.

Parameters:

input_path – Path to qubit file

Returns:

scqubits qubit object

parameter_sweep(qubit_type: str, param_name: str, param_range, fixed_params: dict, property_name: str = 'frequency')[source]

Sweep a parameter and compute resulting properties.

Parameters:
  • qubit_type – Type of qubit

  • param_name – Parameter to sweep

  • param_range – Range of values (list or array)

  • fixed_params – Fixed parameters

  • property_name – Property to compute (frequency, anharmonicity, T1)

Returns:

dict with parameter values and property values

save_qubit(qubit, output_path: str)[source]

Save qubit to JSON file.

Parameters:
  • qubit – scqubits qubit object

  • output_path – Path to save file

visualize(qubit, plot_type: str = 'spectrum', save: bool = True, subtract_ground: bool = False)[source]

Visualize qubit properties.

Parameters:
  • qubit – scqubits qubit object

  • plot_type – Type of visualization (spectrum, wavefunctions, matrix_elements)

  • save – Whether to save the plot

  • subtract_ground – Whether to subtract ground state energy (for spectrum)

visualize_enhanced(qubit, plot_types: list | None = None, save: bool = True, subtract_ground: bool = False)[source]

Create comprehensive visualizations for a qubit.

Parameters:
  • qubit – scqubits qubit object

  • plot_types – List of plot types to generate Options: “spectrum”, “wavefunctions”, “matrix_elements”, “potential” If None, generates all applicable plots

  • save – Whether to save plots

  • subtract_ground – Whether to subtract ground state energy (for spectrum)

Returns:

Mapping plot_type -> file_path

Return type:

dict

Gate Engine: Simulation of quantum gates and dynamics using QuTiP.

class qforge.core.gate_engine.GateEngine[source]

Bases: object

Engine for simulating quantum gates and dynamics.

calculate_gate_fidelity(q1_name: str, q2_name: str, gate_type: str, coupling_type: str, strength: float, duration: float) Dict[str, float][source]

Calculate Average Gate Fidelity using the full propagator. This effectively performs Process Tomography w/o 16 simulations.

calibrate_gate(q1_name: str, q2_name: str, gate_type: str, coupling_type: str, coupling_strength: float, parameter: str = 'duration', range_vals: list = [], **kwargs) Tuple[float, float][source]

Calibrate a gate by sweeping a parameter to maximize fidelity/population. Accepts kwargs (e.g. detuning) passed to simulate().

compare_couplings(q1: str, q2: str, gate: str = 'CNOT', coupling_type: str | None = None, strength: float | None = None, duration: float | None = None) Dict[str, Dict[str, float]][source]

Compare different coupling types for a given gate. Can optionally run a specific single scenario if arguments are provided.

Parameters:
  • q1 – Control qubit name

  • q2 – Target qubit name

  • gate – Gate type (CNOT, CZ)

  • coupling_type – Optional override

  • strength – Optional override

  • duration – Optional override

Returns:

float, ‘phase’: float}

Return type:

Dictionary mapping coupling type to metrics {‘population’

get_control_hamiltonian(gate_type: str, dimension: int) Qobj[source]

Get the control Hamiltonian operator for a specific gate type.

Parameters:
  • gate_type – Type of gate (X, Y, Z, H)

  • dimension – Dimension of the Hilbert space

Returns:

QuTiP Qobj operator

perform_process_tomography(q1_name: str, q2_name: str, gate_type: str = 'CNOT') float[source]

Determine the Process Fidelity of the gate simulation by running it against a complete basis set. (Placeholder logic as simpler method calculate_gate_fidelity is preferred)

perform_state_tomography(state: Qobj, target: Qobj) Dict[str, float][source]

Perform State Tomography Analysis (Fidelity Check).

Real tomography involves measuring <P_i> for all Pauli strings. Here we calculate exact Fidelity and Trace Distance for simulation verification.

Parameters:
  • state – Simulation final state (ket or dm)

  • target – Ideal target state (ket or dm)

Returns:

Dict with ‘fidelity’, ‘trace_distance’

simulate_dynamics(qubit_name: str, gate_type: str, duration: float, noise_model: str = 'none', steps: int = 100) Dict[str, Any][source]

Simulate single-qubit gate dynamics.

Parameters:
  • qubit_name – Name of the target qubit

  • gate_type – Gate to simulate (X, Y, Z, H)

  • duration – Gate duration in ns

  • noise_model – ‘none’ or ‘realistic’

  • steps – Number of time steps

Returns:

Simulation result dictionary

simulate_two_qubit_dynamics(qubit1_name: str, qubit2_name: str, gate_type: str, coupling_type: str, coupling_strength: float, duration: float, steps: int = 100, detuning: float = 0.0) Dict[str, Any][source]

Simulate the dynamics of two coupled qubits under a gate operation.

Parameters:

detuning – Frequency shift amplitude (GHz) for Flux Pulse (CZ).

Utilities

Terminal plotting utility using plotext.

class qforge.utils.terminal_plot.TerminalPlotter[source]

Bases: object

Helper class for terminal-based plotting.

static plot_spectrum(energies, title='Energy Spectrum')[source]

Plot energy spectrum.

Parameters:
  • energies – Array of energy levels

  • title – Plot title

static plot_time_evolution(times, expectations, labels, title='Time Evolution')[source]

Plot time evolution of expectation values.

Parameters:
  • times – Array of time points

  • expectations – List of expectation value arrays

  • labels – List of labels for each expectation value

  • title – Plot title