Demonstration of Quantum Error-Corrected Quantum Phase Estimation

These three modules are used to demonstrate the methods in version one of Quantum Error-Corrected Computation of Molecular Energies. See the knowledge article for more details.

inquanto.experiments.qec_qpe_chem.algorithm

Code for the algorithmic layer of the experiment.

bayesian_update(phi, prior, k_list, beta_list, results, error_rate=None)

Bayesian update (high-level interface taking the BackendResults objects).

Parameters:
  • phi (ndarray[float]) – Equidistant grid points of the phase [0, 2), i.e., pytket conventions.

  • prior (ndarray[float]) – Prior distribution (not necessarily normalized).

  • k_list (list[int]) – List of k, the number of repeats of ctrl-U.

  • beta_list (list[float]) – List of beta, the Rz rotation angle before the X measurement.

  • results (list[BackendResult]) – List of Backend results.

  • error_rate (Optional[Callable[[int], float]], default: None) – Error rate to be passed to the noise-aware likelihood.

Returns:

ndarray[float] – Posterior distribution (normalized).

bootstrap_sampling(phi, ks, betas, ms, error_rate=None, b=1000)

Performs bootstrap resampling.

Parameters:
  • phi (list[float]) – Equidistant grid points of the phase [0, 2), i.e., pytket conventions.

  • ks (list[int]) – List of k, the number of repeats of ctrl-U.

  • betas (list[float]) – List of beta, the Rz rotation angle before the X measurement.

  • ms (list[int]) – List of measurement outcomes {0, 1}.

  • error_rate (Optional[Callable[[int], float]], default: None) – Error rate to be passed to the noise-aware likelihood.

  • b (int, default: 1000) – Number of resampling steps.

Returns:

tuple[float, float] – The mean and variance.

get_ms(k_list, beta_list, results)

Create a list of (k, beta, m).

Parameters:
  • k_list (list[int]) – List of k, the number of repeats of ctrl-U.

  • beta_list (list[float]) – List of beta, the Rz rotation angle before the X measurement.

  • results (list[BackendResult]) – List of Backend results.

Returns:

tuple[list[int], list[float], list[int]] – List of number-of-shots-aware list of (k, beta, m).

get_mu_and_sigma(phi, prior)

Calculate the mean mu and standard deviation sigma.

Parameters:
  • phi (ndarray) – The phase.

  • prior (ndarray) – The prior distribution.

Returns:

tuple[float, float] – Mean and standard deviation.

Notes

This is the ad-hoc implementation not concerning periodicity. If the distribution is not localized, the results may not be accurate.

get_qpde_func(state, ctrl_ext, get_u, n_rounds=1)

Return a function to build Sugisaki’s QPDE circuit.

Reference: K. Sugisaki, et al., Phys. Chem. Chem. Phys. 23, 20152 (2021).

Parameters:
  • state (Circuit) – State preparation circuit.

  • ctrl_ext (Circuit) – Controlled excitation circuit.

  • get_u (Callable[[int], Circuit]) – A function to return a circuit representing the unitary.

  • n_rounds (int, default: 1) – Number of rounds (ancilla qubits) for canonical implemenation.

Returns:

Callable[[int, float], Circuit] – A function to build QPDE circuit.

get_qpe_func(state, get_ctrlu, n_rounds=1)

Return a function to build Kitaev’s (standard) QPE circuit.

Parameters:
  • state (Circuit) – State prearation circuit.

  • get_ctrlu (Callable[[int], Circuit]) – A function to return the circuit representing the controlled unitary.

  • n_rounds (int, default: 1) – Number of rounds.

Returns:

Callable[[int, float], Circuit] – A function to build the QPE circuit.

update_log(phi, prior, ks, betas, ms, error_rate=None)

Update the probability distribution.

Parameters:
  • phi (ndarray[float]) – Equidistant grid points of the phase [0, 2), i.e., pytket conventions.

  • prior (ndarray[float]) – Prior distribution (not necessarily normalized).

  • ks (list[int]) – List of k, the number of repeat of ctrl-U.

  • betas (list[float]) – List of beta, the Rz rotation angle before the X measurement.

  • ms (Sequence[Optional[int]]) – List of measurement outcomes {0, 1}.

  • error_rate (Optional[Callable[[int], float]], default: None) – Error rate to be passed to the noise-aware likelihood.

Returns:

ndarray[float] – Posterior distribution (normalized).

inquanto.experiments.qec_qpe_chem.encode

Encoding utilities.

Code for auto generating logical circuits. This code uses techniques from: “Realization of Real-Time Fault-Tolerant Quantum Error Correction” https://doi.org/10.1103/PhysRevX.11.041058 “Protecting Expressive Circuits with a Quantum Error Detection Code” https://doi.org/10.1038/s41567-023-02282-2 “Benchmarking logical three-qubit quantum Fourier transform encoded in the Steane code on a trapped-ion quantum computer” https://doi.org/10.48550/arXiv.2404.08616

class EncodeData(n_qubits: int, n_bits: int)

Bases: NamedTuple

Encode data to be used by the automated workflow driver.

Parameters:
  • n_qubits – Number of logical qubits.

  • n_bits – Number of logical classical bits.

n_bits: int

Number of logical classical bits.

n_qubits: int

Number of logical qubits.

class EncodeOptions(rz_mode: RzMode = RzMode.DIRECT, rz_options: RzOptionsRUS | RzOptionsBinFracNonFT | RzOptionsBinFracPartFT | RzOptionsBinFracMeasFT | None = None, ft_prep: bool = False, n_rus_prep: int = 1, ft_prep_synd: bool = False, n_rus_synd: int = 1, ft_prep_gate: bool = False, n_rus_gate: int = 1)

Bases: NamedTuple

Encdode options for the Steane code.

Parameters:
  • rz_mode – Rz operation mode. Default is the iceberg direct mode.

  • rz_options – Options for the Rz operation.

  • ft_prep – Enable FT state preparation (i.e. Goto state preparation) for the data register.

  • n_rus_prep – Number of RUS for the FT state preparation.

  • ft_prep_synd – Enable FT state preparation for the ancilla register for the Steane QEC.

  • ft_rus_synd – Number of RUS for the FT state preparation for the Steane QEC.

  • ft_prep_gate – Enable FT state preparation for the Rz gate teleportation gadget.

  • ft_rus_gate – Number of RUS for the FT state preparation for the Rz gate teleportation.

ft_prep: bool

Enable FT state preparation (i.e. Goto state preparation) for the data register.

ft_prep_gate: bool

Enable FT state preparation for the Rz gate teleportation gadget.

ft_prep_synd: bool

Enable FT state preparation for the ancilla register for the Steane QEC.

n_rus_gate: int

Number of RUS for the FT state preparation.

n_rus_prep: int

Number of RUS for the FT state preparation.

n_rus_synd: int

Number of RUS for the FT state preparation.

rz_mode: RzMode

Rz operation mode. Default is the iceberg direct mode.

rz_options: UnionType[RzOptionsRUS, RzOptionsBinFracNonFT, RzOptionsBinFracPartFT, RzOptionsBinFracMeasFT, None]

Options for the Rz operation.

class InterpretOptions(readout_mode: ReadoutMode = ReadoutMode.Correct)

Bases: NamedTuple

Options for the interpret function to be used by the workflow driver.

readout_mode: ReadoutMode

Specifies the readout mode.

class ReadoutMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Readout interpretation mode.

Correct = 2

Perform the error correction based on the lookup table.

Detect = 1

Post-select the measurement outcomes that remain in the code space.

Raw = 0

Interpret the raw measurement outcomes as (-1) ** sum(bits).

class RzMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Rz encoding mode.

BIN_FRAC_MEAS_FT = 'bin_frac_meas_ft'

Indirect (gate teleportation) and deterministic operation with the angle in binary fraction (MEAS-FT).

BIN_FRAC_NON_FT = 'bin_frac_non_ft'

Indirect (gate teleportation) and deterministic operation with the angle in binary fraction (non-FT).

BIN_FRAC_PART_FT = 'bin_frac_part_ft'

Indirect (gate teleportation) and deterministic operation with the angle in binary fraction (partially FT).

DIRECT = 'direct'

Direct (iceberg-code-style) operation, which is low-cost but not scalable.

class RzOptionsBinFracMeasFT(max_bits: int = 10)

Bases: NamedTuple

Options for the RzMode.BIN_FRAC_MEAS_FT.

Parameters:

max_bits – Maximum number of bits (i.e., max_bits - 2 = max_rus).

max_bits: int

Maximum number of bits (i.e., max_bits - 2 = max_rus).

class RzOptionsBinFracNonFT(max_bits: int = 10)

Bases: NamedTuple

Options for the RzMode.BIN_FRAC_NON_FT.

Parameters:

max_bits – Maximum number of bits (i.e., max_bits - 2 = max_rus).

max_bits: int

Maximum number of bits (i.e., max_bits - 2 = max_rus).

class RzOptionsBinFracPartFT(max_bits: int = 10, max_rus: int = 1)

Bases: NamedTuple

Options for the RzMode.BIN_FRAC_PART_FT and RzMode.BIN_FRAC_PART_FT_GOTO.

Parameters:
  • max_bits – Maximum number of bits (i.e., max_bits - 2 = max_rus).

  • n_rus – Number of RUS if PFT implementation is used.

max_bits: int

Maximum number of bits (i.e., max_bits - 2 = max_rus).

max_rus: int

Number of RUS if PFT implementation is used.

class RzOptionsRUS(max_rus: int = 8)

Bases: NamedTuple

Options for the RzMode.RUS.

Parameters:

max_rus – Maximum number of repeat-until-success.

max_rus: int

Maximum number of repeat-until-success.

encode(circ, options=EncodeOptions())

Encode a logical circuit according to the provided options.

Parameters:
  • circ (Circuit) – Input logical circuit.

  • options (EncodeOptions, default: EncodeOptions()) – Encode options.

Returns:

Circuit – (Encoded circuit, number of shots, and encoding data)

interpret(result, options=InterpretOptions())

Interpret physical results from a backend, according to the provided options.

Parameters:
  • result (BackendResult) – Backend result in the physical space.

  • options (InterpretOptions, default: InterpretOptions()) – Interpret options – see InterpretOptions for details.

Returns:

BackendResult – Results in the logical space.

inquanto.experiments.qec_qpe_chem.experiment

Collection of the experimental setup.

Note

Much of the code in this module are specific to this particular project, caution should be used when generalizing.

class BenchmarkInput(k_list, encode, interpret, encode_options, intepret_options, qec_level, pft_rz)

Bases: NamedTuple

encode: Callable[[Circuit, Optional[EncodeOptions]], Circuit]

Method for encoding circuits.

encode_options: Optional[EncodeOptions]

Options for encoding circuits.

intepret_options: Optional[InterpretOptions]

Options for interpreting results.

interpret: Callable[[BackendResult, Optional[InterpretOptions]], BackendResult]

Method for interpreting results.

k_list: list[int]

A list of k values to be used in circuit generation.

pft_rz: bool

Whether to use a partially fault-tolerant Rz operation.

qec_level: int

The level of QEC to perform.

class BenchmarkResult(p0, p0_unc, n_shots)

Bases: NamedTuple

n_shots: list[int]

Number of shots.

p0: list[float]

Probability of obtaining 0.

p0_unc: list[float]

Probability of obtaining 0 uncorrected.

class ChemData(CZ, CX, CI, DELTA_T, MAX_BITS=5, FCI_ENERGY=None, APPROX_ENERGY=None, ANSATZ_PARAM=None)

Bases: object

Parameters:
ANSATZ_PARAM: Optional[list[float]] = None

The (Y,Z) rotation parameters of the ansatz state to be prepared.

APPROX_ENERGY: Optional[float] = None

The 1-step Trotter energy (determined from the ground state value of the Trotterized unitary evolution operator, with 1 Trotter step.

APPROX_PHASE: Optional[float]

The 1-step Trotter phase (the eigenphase of the Trotterized unitary evolution operator, with 1 Trotter step).

CI: float

The additional constant phase to be applied (the Pauli I coefficient).

CX: float

The angle of the CX rotation gate (the Pauli X coefficient).

CZ: float

The angle of the CZ rotation gate (the Pauli Z coefficient).

DELTA_T: float

The total evolution time.

FCI_ENERGY: Optional[float] = None

The full configuration interaction reference energy.

HF_STATE: Optional[int]

1 if the Hartree-Fock state is the |1> state, 0 if the Hartree-Fock state is the |0> state.

MAX_BITS: int = 5

The number of bits resolution for discretizing angles.

classmethod from_qubit_operator(qubit_operator, delta_t=None, max_bits=5, fci_energy=None, approx_energy=None, ansatz_param=None)

Generates a ChemData object from an InQuanto QubitOperator.

By default, this will leave classically intractably calculable quantities unfilled, though these can be explicitly passed as below. Consider the automated methods of this class for automatic determination of these quantities.

Parameters:
  • qubit_operator (QubitOperator) – The Hamiltonian of interest.

  • delta_t (Optional[float], default: None) – The total evolution time.

  • max_bits (int, default: 5) – The number of bits resolution for discretizing angles.

  • fci_energy (Optional[float], default: None) – The full configuration interaction reference energy.

  • approx_energy (Optional[float], default: None) – The 1-step Trotter energy.

  • ansatz_param (Optional[list[float]], default: None) – The (Y,Z) rotation parameters of the ansatz state to be prepared.

Returns:

ChemData – A ChemData object for the examination of the provided Hamiltonian using the pFT routines herein.

classmethod from_qubit_operator_automated(qubit_operator, delta_t=None, max_bits=5)

Generates a ChemData from a qubit operator with all fields filled automatically.

Danger

This determines approximate quantities through direct diagonalization of the Hamiltonian, and thus requires exponential runtime.

Parameters:
  • qubit_operator (QubitOperator) – The Hamiltonian of interest.

  • delta_t (Optional[float], default: None) – The total evolution time.

  • max_bits (int, default: 5) – The number of bits resolution for discretizing angles.

Returns:

ChemData – A ChemData object for the examination of the provided Hamiltonian, with all fields filled automatically.

class IqpeInput(chem_data, k_list, beta_list, encode, interpret, encode_options, intepret_options, qec_level, pft_rz)

Bases: NamedTuple

beta_list: list[float]

A list of initial beta values to be used in the experiment.

chem_data: ChemData

The data specifying the chemical aspects of the experiment.

encode: Callable[[Circuit, Optional[EncodeOptions]], Circuit]

A method for performing encoding.

encode_options: Optional[EncodeOptions]

Options for performing encoding.

intepret_options: Optional[InterpretOptions]

Options for interpreting physical results.

interpret: Callable[[BackendResult, Optional[InterpretOptions]], BackendResult]

A method for interpreting physical results.

k_list: list[int]

A list of k values to be used in the experiment.

pft_rz: bool

Whether to perform partially fault-tolerant Rz operations.

qec_level: int

The level of QEC to be used in the experiment.

build_benchmark_circuits(chem_data, k_list, pft_rz, qec_level)

Builds benchmarking circuits.

Parameters:
  • chem_data (ChemData) – The specification of the simulation parameters.

  • k_list (list[int]) – A list of k values to be used in circuit generation.

  • pft_rz (bool) – Whether to use partially fault-tolerant Rz operation.

  • qec_level (int) – The level of QEC to perform.

Returns:

list[Circuit] – The benchmarking circuits.

build_encode_benchmark_circuits(chem_data, params)

Builds and encodes benchmarking circuits.

Parameters:
  • chem_data (ChemData) – The specification of the simulation parameters.

  • params (BenchmarkInput) – The parameters of how to perform the benchmarking experiment.

Returns:

list[Circuit] – The benchmarking circuits.

build_encode_benchmark_circuits_no_barriers(chem_data, params)

Builds and encodes benchmarking circuits, without adding pytket barriers to prevent reduction through compilation.

Parameters:
  • chem_data (ChemData) – The specification of the simulation parameters.

  • params (BenchmarkInput) – The parameters of how to perform the benchmarking experiment.

Returns:

list[Circuit] – The benchmarking circuits.

build_encode_iqpe_circuits(params)

Build and encode IQPE circuits.

Parameters:

params (IqpeInput) – IQPE input parameters.

Returns:

list[Circuit] – Encoded IQPE circuits.

build_iqpe_circuits(chem_data, k_list, beta_list, pft_rz, qec_level)

Build IQPE circuits.

Parameters:
  • chem_data (ChemData) – The data specifying the chemical aspects of the experiment.

  • k_list (list[int]) – The list of k values to be used in the experiment.

  • beta_list (list[float]) – The list of initial beta values to be used in the experiment.

  • pft_rz (bool) – Whether to perform partially fault-tolerant Rz operations.

  • qec_level (int) – The level of QEC to be used in the experiment.

Returns:

list[Circuit] – A list of IQPE circuits.

interpret_process_benchmark_results(results, params)

Interprets and processes benchmark results.

Parameters:
  • results (list[BackendResult]) – Raw results from the backend.

  • params (BenchmarkInput) – The parameters of how to perform the benchmarking experiment.

Returns:

BenchmarkResult – The results of the benchmarking experiment.

interpret_process_iqpe_results(results, params)

Interpret and process results from IQPE.

Parameters:
  • results (list[BackendResult]) – Raw results from backend.

  • params (IqpeInput) – IQPE input parameters.

Returns:

tuple[list[int], list[float], list[int]] – IQPE results.

process_benchmark_results(results)

Processes benchmark results.

Parameters:

results (list[BackendResult]) – Raw results from the backend.

Returns:

BenchmarkResult – The results of the benchmarking experiment.

process_iqpe_results(results, k_list, beta_list)

Process results from IQPE.

Parameters:
  • results (list[BackendResult]) – Raw results from backend.

  • k_list (list[int]) – The list of k values used in the experiment.

  • beta_list (list[float]) – The list of beta values used in the experiment.

Returns:

tuple[list[int], list[float], list[int]] – IQPE results.