Skip to main content

Crate ctrl_freeq

Crate ctrl_freeq 

Source
Expand description

§ctrl-freeq

Quantum gate and pulse design by optimal control. A Rust port of the Python ctrl-freeq package.

A control pulse is expanded in a small basis (Chebyshev, Legendre, Fourier, …), propagated through a batch of drift Hamiltonians that sample the uncertainty in offsets, couplings and field strength, and scored by the mean fidelity to a target state, or by the average gate fidelity to a target gate. The optimiser adjusts the basis coefficients; gradients and Hessians come from the crate’s own reverse-mode automatic differentiation.

analyse() then gives the data the plots need: the pulses, the state dynamics, the excitation profile, and the population outside the computational subspace. A run also reports each qubit’s peak amplitude as a fraction of its maximum Rabi frequency, which the cost penalises rather than enforces.

§Quick start

use ctrl_freeq::config::{Config, examples};
use ctrl_freeq::optim::NoProgress;

// One of the Python package's bundled configurations: three initial states on one qubit.
let json = examples().iter().find(|e| e.0 == "single_qubit_parameters_multiple_initial_targ").unwrap().1;
let mut cfg = Config::from_json(json)?;
cfg.seed = Some(7); // reproducible
cfg.optimization.max_iter = 20;
let result = ctrl_freeq::run(&cfg, &mut NoProgress)?;
assert!(result.fidelity > 0.5);
let plots = ctrl_freeq::analyse(&cfg, &result)?;
assert_eq!(plots.pulses.len(), 1);

§Where to look

  • config: the configuration, in the Python package’s JSON schema.
  • run() and analyse(): optimise, then get the data for plots.
  • optim: the optimisers and the interface a new one implements.
  • hamiltonian and basis: the physical platforms and waveform bases, and how to add one.
  • objective and autodiff: the cost function and the differentiation underneath it.

§Threads

With the parallel feature, on by default, the batch elements and the Hessian’s columns are evaluated on rayon’s thread pool. Results are bit-for-bit the same on one thread as on many. wasm32 has no threads and always runs sequentially.

Re-exports§

pub use analysis::Analysis;
pub use analysis::analyse;
pub use config::Config;
pub use error::Error;
pub use error::Result;
pub use run::RunResult;
pub use run::run;

Modules§

analysis
What the plots need after a run: the pulses, the state dynamics, and the excitation profile.
autodiff
Automatic differentiation.
basis
Basis functions for the pulse waveforms.
config
The optimisation problem as the Python package writes it: the same JSON schema, field for field.
error
The crate’s error type.
hamiltonian
Hamiltonian models: the physical platforms.
linalg
Small dense linear algebra generic over Scalar: matrices, a linear solve, the matrix exponential and the adjoint of its derivative.
objective
The cost function: waveform → modulation → control amplitudes → evolution of every batch element → fidelity.
optim
Optimisation: the objective and optimiser interfaces, the optimiser registry, and the algorithms.
run
One call from a configuration to an optimised pulse.
setup
From a Config to the numbers the optimiser works with - the Python Initialise.
time
Clock shim.