inquanto.algorithms

Variational

class AlgorithmFermionicAdaptVQE(pool, state, hamiltonian, minimizer, auxiliary_operator=None, n_iterations=100, tolerance=1e-3, disp=False, qubit_mapping=QubitMappingJordanWigner())

Bases: AlgorithmAdaptVQE

Fermionic ADAPT – an algorithm for approximating the ground-state energy of a fermionic system.

The algorithm finds a compact Pauli exponential ansatz that is capable of approximating the ground-state energy. The implementation is based on work in arXiv:1812.11173 .

Parameters:
  • pool (FermionOperatorList) – Holds the pool of Pauli terms which go the TrotterAnsatz object.

  • state (FermionState) – Initial (para-)fermionic reference state for the chemical system in question (usually the HF determinant).

  • hamiltonian (FermionOperator) – The Hermitian operator to measure for the lowest eigenvalue.

  • minimizer (GeneralMinimizer) – Variational minimizer to use for the ADAPT experiment.

  • auxiliary_operator (list[FermionOperator], default: None) – Additional Hamiltonian operators to evaluate in parallel.

  • n_iterations (int, default: 100) – Number of iterations before termination.

  • tolerance (float, default: 1e-3) – Expectation value of commutation between pool and Hamiltonian at which loop is stopped.

  • disp (bool, default: False) – If the algorithm should display variational data every iteration.

  • qubit_mapping (QubitMapping, default: QubitMappingJordanWigner()) – Fermion-to-qubit mapping scheme to transform fermionic operators and reference state.

build(protocol_expectation, protocol_pool_metric, protocol_gradient=None)

Build the algorithm using the provided protocols.

Parameters:
  • protocol_expectation (EvaluatorRunnerMixin) – The protocol used for expectation value calculation.

  • protocol_pool_metric (EvaluatorRunnerMixin) – The protocol used to determine the excitation selection metric.

  • protocol_gradient (Optional[EvaluatorRunnerMixin], default: None) – The protocol used for gradient calculation.

Returns:

AlgorithmAdaptVQE – self

property final_parameters: SymbolDict

Returns the optimised ansatz parameters.

generate_report()

Return a dictionary giving experimental results.

Return type:

dict

get_ansatz(state, fermion_ansatz_type=FermionSpaceStateExpChemicallyAware)

Returns an ansatz built from symbol-containing operators of the fermionic pool.

Parameters:
Returns:

Union[FermionSpaceStateExp, FermionSpaceStateExpChemicallyAware] – A new ansatz object.

get_exponents_with_symbols()

Returns a symbol-containing sublist of the fermionic pool operator list.

Return type:

FermionOperatorList

run()

Perform the ADAPT experiment.

After execution, a TrotterAnsatz instance, optimized energy and final parameters will be available.

Return type:

None

class AlgorithmAdaptVQE(pool, state, hamiltonian, minimizer, auxiliary_operator=None, n_iterations=100, tolerance=1e-3, disp=False)

Bases: object

ADAPT – An algorithm for approximating the ground-state energy of a chemical or material system.

The algorithm finds a compact Pauli exponential ansatz that is capable of approximating the ground-state energy. The implementation is based on work in arXiv:1812.11173 .

Parameters:
  • pool (QubitOperatorList) – Holds the pool of Pauli terms which go to the TrotterAnsatz object.

  • state (QubitState) – Initial (para-)fermionic reference state for the chemical system in question (usually the HF determinant).

  • hamiltonian (QubitOperator) – The Hermitian operator to measure for the lowest eigenvalue.

  • minimizer (GeneralMinimizer) – Variational minimizer to use for the ADAPT experiment.

  • auxiliary_operator (list[QubitOperator], default: None) – Additional Hamiltonian operators to evaluate in parallel.

  • n_iterations (int, default: 100) – Number of iterations before termination.

  • tolerance (float, default: 1e-3) – Expectation value of commutation between pool and Hamiltonian at which loop is stopped.

  • disp (bool, default: False) – If the algorithm should display variational data every iteration.

build(protocol_expectation, protocol_pool_metric, protocol_gradient=None)

Build the algorithm using the provided protocols.

Parameters:
  • protocol_expectation (EvaluatorRunnerMixin) – The protocol used for expectation value calculation.

  • protocol_pool_metric (EvaluatorRunnerMixin) – The protocol used to determine the excitation selection metric.

  • protocol_gradient (Optional[EvaluatorRunnerMixin], default: None) – The protocol used for gradient calculation.

Returns:

AlgorithmAdaptVQE – self

property final_parameters: SymbolDict

Returns the optimised ansatz parameters.

generate_report()

Return a dictionary giving experimental results.

Return type:

dict

run()

Perform the ADAPT experiment.

After execution, a TrotterAnsatz instance, optimized energy and final parameters will be available.

Return type:

None

class AlgorithmIQEB(pool, state, hamiltonian, minimizer, n_iterations=100, n_grads=10, energy_tolerance=1.0e-10, disp=False, verbose=False)

Bases: AlgorithmAdaptVQE

An ADAPT-like algorithm in which operators correspond to parafermionic qubit excitations.

The Iterative Qubit-Excitation-Based (IQEB) algorithm is described in arXiv:2011.10540. The qubit excitations obey different commutation relations and so do not require tensor product over Z rotations which occur in Jordan-Wigner transformed UCC operators. Convergence is reached to by checking energy reduction between iterations, while gradients are used to narrow down the pool of operators. The ParaFermionSpace generators are used with this class.

Parameters:
  • pool (QubitOperatorList) – Holds the pool of qubit excitation terms which go the TrotterAnsatz object.

  • state (QubitState) – Initial (para-)fermionic reference state for the chemical system in question (usually the HF determinant).

  • hamiltonian (QubitOperator) – The hermitian operator to measure for the lowest eigenvalue.

  • minimizer (GeneralMinimizer) – Variational minimizer to use for the ADAPT experiment.

  • n_iterations (int, default: 100) – Number of iterations before termination.

  • n_grads (int, default: 10) – Number of terms to narrow down the pool, based on gradients. Each IQEB iteration will run n_grads VQEs, one VQE for each of the n_grads largest gradient terms.

  • energy_tolerance (float, default: 1.0e-10) – Condition of termination of IQEB algorithm. Corresponds to threshold energy difference between IQEB iterations. The default is 1e-10 (in Hartrees).

  • disp (bool, default: False) – If the algorithm should display variational data every iteration.

  • verbose (bool, default: False) – Output information, showing information on IQEB run.

build(protocol_expectation, protocol_pool_metric, protocol_gradient=None)

Build the algorithm using the provided protocols.

Parameters:
  • protocol_expectation (EvaluatorRunnerMixin) – The protocol used for expectation value calculation.

  • protocol_pool_metric (EvaluatorRunnerMixin) – The protocol used to determine the excitation selection metric.

  • protocol_gradient (Optional[EvaluatorRunnerMixin], default: None) – The protocol used for gradient calculation.

Returns:

AlgorithmAdaptVQE – self

property final_parameters: SymbolDict

Returns the optimised ansatz parameters.

generate_report()

Return a dictionary of results after running the algorithm.

Return type:

dict

run(compiler_passes=None)

Run the ADAPT-like IQEB algorithm.

This uses gradients to narrow down the pool of operator exponents. From this smaller pool, a number of VQEs are performed, and the VQE with the biggest energy reduction is used to choose the operator that gets appended to the final ansatz. The algorithm stops when the energy reduction is smaller than a threshold.

Each IQEB iteration is indexed by m, while each VQE (inside an IQEB iteration) is indexed by p.

After execution, a TrotterAnsatz instance, optimized energy and final parameters will be available.

The parameter symbols (r) of terms in the ansatz are labelled as r_m_p(_sc), where ‘sc’ stands for spin complement.

Parameters:

compiler_passes (Optional[BasePass], default: None) – Circuit optimisation pass applied at each iteration of the algorithm.

Return type:

None

class AlgorithmVQE(minimizer, objective_expression, *, gradient_expression=None, initial_parameters=None, auxiliary_expression=None)

Bases: object

Variational quantum eigensolver algorithm.

An algorithm for finding ground state energies of molecular Hamiltonians.

Parameters:
  • objective_expression (ExpectationValue) – A preconfigured ExpectationValue expression to evaluate the ground-state energy of some trial wave function and hamiltonian.

  • minimizer (GeneralMinimizer) – Variational classical minimizer to perform the parameter search.

  • initial_parameters (Optional[SymbolDict], default: None) – A set of initial ansatz parameters.

  • gradient_expression (Optional[ExpectationValueDerivative], default: None) – An expression to evaluate the gradient of the objective function.

  • auxiliary_expression (Optional[ComputableNode], default: None) – Additional expressions to evaluate alongside the energy.

build(protocol_objective, protocol_gradient=None)

Build the VQE experiment.

Provide objects required to estimate the expectation value of the ansatz, and gradient estimation used for minimization.

Parameters:
  • protocol_objective (EvaluatorRunnerMixin) – The protocol used for energy expectation value estimation.

  • protocol_gradient (Optional[EvaluatorRunnerMixin], default: None) – The protocol used for energy gradient estimation.

Returns:

AlgorithmVQE – self

property final_evaluated_auxiliary_expression: tuple[float, RestrictedOneBodyRDM]

Expectation value result of VQE experiment on auxiliary expression.

property final_evaluated_objective_expression: float

Expectation value of the objective function using the final set of parameters.

property final_parameters: SymbolDict

Parameters used to evaluate final expectation value.

property final_value: float

Expectation value result of VQE experiment.

generate_report()

Return a dictionary giving experimental results.

Return type:

dict

run()

Perform the VQE experiment.

Results may be queried with generate_report()

Return type:

AlgorithmVQE

class AlgorithmVQD(objective_expression, overlap_expression, weight_expression, minimizer, initial_parameters, vqe_value, vqe_parameters, n_vectors)

Bases: object

Algorithm to sequentially obtain the excited states of a Hamiltonian.

The algorithm orthogonally constrains the previously found eigenstates (see Quantum 3, 156 (2019)), where each eigenstate is found with a separate VQE experiment. A number-conserving ansatz should be used for VQD. Sometimes, spin-crossing excitations are required.

Parameters:
  • objective_expression (ExpectationValue) – A preconfigured ExpectationValue expression to evaluate the excited state energy of some trial wave function and Hamiltonian.

  • overlap_expression (OverlapSquared) – Computable expression to calculate the square of the overlap between two trial states.

  • weight_expression (ExpectationValue) – Computable expression used for the deflation scheme, the penalty applied due to the difference between the initial expectation value of this expression and the \(n - 1\) excited state energy.

  • minimizer (GeneralMinimizer) – Variational classical minimizer to perform the parameter search.

  • initial_parameters (SymbolDict) – A set of initial ansatz parameters for the objective and weight expressions.

  • vqe_value (float) – Energy of the reference state.

  • vqe_parameters (SymbolDict) – Parameters of the reference (ground) state.

  • n_vectors (int) – Number of subsequent excited states to generate.

build(objective_protocol, weight_protocol, overlap_protocol, n_shots=8192)

Build the VQD experiment.

Provide objects required to estimate the expectation value of the ansatz, weighting of Hamiltonian eigenstates, and calculation of the overlap between states for the VQE experiment.

Parameters:
  • objective_protocol (EvaluatorRunnerMixin) – The protocol used for energy expectation value estimation.

  • weight_protocol (EvaluatorRunnerMixin) – The protocol used to estimate the weighting of eigenstates of the Hamiltonian.

  • overlap_protocol (EvaluatorRunnerMixin) – The protocol used for overlap estimation between successive states.

  • n_shots (int, default: 8192) – The number of shots used for expectation value estimation.

Returns:

AlgorithmVQD – self

property final_parameters: list[SymbolDict]

Parameters used to evaluate final expectation value.

property final_values: list[float]

Expectation value result of VQD experiment.

generate_report()

Return a dictionary giving experimental results.

Return type:

dict

run()

Perform the VQD experiment.

Results can be queried with generate_report().

Returns:

AlgorithmVQD – self

Non-variational

class AlgorithmQSE(computable_qse_matrices, parameters)

Bases: object

Quantum Subspace Expansion algorithm.

The implementation here is based on work in arXiv:1603.05681.

Parameters:
  • computable_qse_matrices (QSEMatricesComputable) – Computable to return the matrix representation of a hermitian operator, \(H\) and overlap matrix, \(S\).

  • parameters (SymbolDict) – Circuit parameters from which the subspace is generated.

build(protocol)

Build the algorithm using the provided protocols.

Parameters:

protocol (EvaluatorRunnerMixin) – The protocol to evaluate matrix elements.

Returns:

AlgorithmQSE – self

property final_states

Final states in QSE computable.

property final_values

Final expectation values of QSE computable.

generate_report()

Return a dictionary giving experimental results.

Return type:

dict

run()

Perform the QSE experiment. Results can be queried with generate_report().

Return type:

None

class AlgorithmSCEOM(computable_sceom_matrix, parameters=None)

Bases: object

Quantum Self Consistent Equation of Motion.

The implementation here is based on work in https://doi.org/10.1039/D2SC05371C.

Parameters:
  • computable_sceom_matrix (SCEOMMatrixComputable) – Computable to return the matrix representation of a Hermitian operator with respect to the correlated excited states, \(M\) matrix.

  • parameters (Optional[SymbolDict], default: None) – Circuit parameters from VQE run.

build(protocol)

Build the algorithm using the provided protocols.

Parameters:
  • objective_protocol – The protocol to evaluate matrix elements.

  • protocol (EvaluatorRunnerMixin)

Returns:

AlgorithmSCEOM – self

property final_states

Final states in QSCEOM computable.

property final_values

Final eigenvalues of QSCEOM computable.

generate_report()

Return a dictionary giving experimental results.

Return type:

dict

get_dataframe_sceom_analysis()

Returns a dataframe containing expectation values and overlaps with SCEOM states. :rtype: DataFrame

Note

The expectation values and overlaps are calculated with the default_evaluate() computable method.

Warning

This feature is under development due to numerical instabilities issues.

Raises:

RuntimeError – If :meth:final_states is None.

print_sceom_states()

Prints the SCEOM excited states.

Return type:

None

run()

Perform the SCEOM experiment. Results can be queried with generate_report().

Return type:

None

Phase estimation

class AlgorithmDeterministicQPE(ansatz, evolution_operator_exponents)

Bases: object

Quantum Phase Estimation (QPE), for estimating the eigenstate energies of molecular Hamiltonians.

This class corresponds to “deterministic” forms of QPE - those which do not rely on stochasticity or statistical inference based on measurement outcomes. Examples include canonical QPE and certain variants of iterative QPE.

To use this algorithm, provide an ansatz object and a QubitOperatorList corresponding to the unitary evolution operator of the Hamiltonian to be simulated. The ansatz object is used for state preparation, and should be a state which is likely to have high overlap with the true eigenstate of interest. The QubitOperatorList must have terms within it corresponding to individual exponents of an exponential product which may be simulated on a quantum computer. Typically, this will mean that the QubitOperatorList will be generated through Trotterization. The QubitOperatorList must be scaled through multiplying by a total evolution time \(t\), such that the obtained phase will be in the interval \((0,2\pi]\)

Once created, the computational primitives must be built with the build() method. Here, a protocol must be specified providing detail of how to create the specific quantum circuits corresponding to a particular form of QPE. For instance, CanonicalPhaseEstimation will create canonical QPE circuits. See the protocol documentation, or the examples, for details as to which protocols are available.

Please see the documentation for example usage.

Parameters:
  • ansatz (GeneralAnsatz) – An ansatz state to be used for the state preparation.

  • evolution_operator_exponents (QubitOperatorList) – A list of exponents corresponding to an exponential product representing the evolution operator of the Hamiltonian of interest. This will typically be generated through Trotterization.

Notes

The value of the parameter \(t\) of the time evolution operator \(e^{-iHt}\) must be given in a unit of half turn, i.e., \(t =\) time * pi to be compatible with the pytket convention.

build(protocol, phase_calculation_protocol=None)

Build the QPE algorithm using the specified protocols and computational details.

Here, a Protocol object must be specified identifying how the relevant quantum circuits are to be constructed. These will typically correspond to a particular “flavour” of quantum phase estimation - for instance, CanonicalPhaseEstimation for canonical phase estimation. Optionally, a second Protocol derived from PhaseEstimator may be specified, to control how a phase is determined from the observed experimental results. By default, this will proceed by taking the most likely measurement outcome.

Parameters:
  • protocol (ProtocolQPE) – A computational protocol defining how the QPE circuits are to be built, typically corresponding to a “flavour” of QPE.

  • phase_calculation_protocol (Optional[PhaseEstimator], default: None) – An optional protocol, derived from PhaseEstimator, used for determining the phase from the raw measurement outcomes. By default, this will calculate the phase from the most common measurement outcome.

Returns:

AlgorithmDeterministicQPE – self.

final_energy(time, phase_estimator_protocol=None)

Returns the energy, given a specified total evolution time.

Parameters:
  • time (float) – The total evolution time of the original unitary evolution operator.

  • phase_estimator_protocol (Optional[PhaseEstimator], default: None) – An optional protocol used to override how the phase is derived from raw measurement outcomes. By default, this will use the protocol specified at build-time.

Returns:

float – The calculated energy, given the provided total evolution time.

final_phase(phase_estimator_protocol=None)

Returns the final phase estimate given by the algorithm run.

Parameters:

phase_estimator_protocol (Optional[PhaseEstimator], default: None) – An optional protocol used to override how the phase is derived from raw measurement outcomes. By default, this will use the protocol specified at build-time.

Returns:

The calculated phase.

generate_report()

Return a dictionary giving experimental results.

Return type:

dict[str, Any]

launch_experiment()

Launch the jobs through the protocol object asynchronously.

This method may be useful when the job is run on a remote backend.

Returns:

list[ResultHandle] – List of result handles.

retrieve_experiment(handles_list=None)

Retrieve the backend results through the protocol.

Parameters:
Returns:

AlgorithmDeterministicQPE – self.

Raises:

RuntimeError – If the experiment has not been launched.

run()

Perform the QPE experiment.

Results may be queried with generate_report(), final_phase() or final_energy().

Returns:

AlgorithmDeterministicQPE – self.

run_experiment()

Perform the QPE experiment.

Results may be queried with generate_report(), final_phase() or final_energy().

Returns:

AlgorithmDeterministicQPE – self.

class AlgorithmInfoTheoryQPE(resolution, k_max, n_samples, prior=None, error_rate=None, verbose=0)

Bases: object

Execute information theory QPE algorithm.

Reference:

This algorithm class performs maximum likelihood estimation of the phase \(\phi\).

The noise-aware likelihood function is expressed as

(121)\[P(m|\phi,k,\beta) = \frac{1 + (1 - q(k)) (-1)^{m} \cos(k\phi + \beta)}{2}\]

where \(q(k) \in [0, 1]\) is the error rate as a function of \(k\).

Parameters:
  • resolution (int) – Number of grid points to resolve the phase.

  • k_max (int) – Cap of the circuit depth parameter \(k\).

  • n_samples (int) – Number of measurement samples.

  • prior (Optional[ndarray], default: None) – Prior distribution. If not given, uniform distribution is used.

  • error_rate (Optional[Callable[[int], float]], default: None) – Error rate used for the noise-aware likelihood. If not given, \(q(k)=0\) is used.

  • verbose (int, default: 0) – Control verbosity.

build(protocol)

Set the protocol and build the algorithm.

Parameters:

protocol (BaseIterativePhaseEstimation) – Iterative QPE protocol.

Returns:

AlgorithmInfoTheoryQPE – self.

final_pdf(phi)

Return the PDF as a function of phase.

Parameters:

phi (ndarray) – Grid representation of the phase in \([0, 2)\) (pytket convention).

Returns:

ndarray – Probability distribution function.

final_value()

Return the phase estimate in the unit of half turn.

Returns:

tuple[float, float] – Mean \(\mu\) and standard deviation \(\sigma\).

join(handles_list)

Retrieve the results through the protocol.

Parameters:

handles_list (Union[list[tuple[int, float, list[ResultHandle]]], list[tuple[int, float, list[BackendResult]]]]) – List of (k, beta, handles/handles).

Return type:

None

run()

Run the algorithm.

run_async()

Launch the jobs through the protocol object asynchronously.

This API may be useful when the job is run on a remote backend.

Returns:

list[tuple[int, float, list[ResultHandle]]] – List of (k, beta, handles/results).

class AlgorithmKitaevQPE(n_bits, n_extra_bits=2, verbose=0)

Bases: object

Execute Kitaev’s QPE algorithm.

The parameter n_bits governs the highest unitary power that will be applied in the iterative procedure i.e. if n_bits = k, then the largest circuit will involve the application of \(U^{2^k}\). Obtaining a more precise estimate of the phase is possible with the n_extra_bits parameter; in this case the circuits will be sampled repeatedly to obtain a result with n_bits + n_extra_bits bits of precision. Note that sampling in this way scales unfavourably, and many shots may be required to obtain extra precision in this manner.

Parameters:
  • n_bits (int) – Number of bits to be estimated.

  • n_extra_bits (int, default: 2) – Number of extra bits to be estimated.

  • verbose (int, default: 0) – Verbosity level.

build(protocol)

Set the protocol and build the algorithm.

Parameters:

protocol (BaseIterativePhaseEstimation) – Iterative QPE protocol.

Returns:

AlgorithmKitaevQPE – self

final_value()

Final value of the phase estimate.

Returns:

tuple[float, float] – Phase estimate and the precision.

join(handles_mapping)

Retrieve the backend results through the protocol.

Parameters:
Return type:

None

run()

Run the algorithm.

Return type:

None

run_async()

Run the jobs asynchnonously.

This method may be useful when the job is run on a remote backend.

Returns:

list[tuple[int, float, list[ResultHandle]]] – List of job IDs (k, beta, handles/results).

Time evolution

class AlgorithmVQS(integrator, expressions, initial_parameters)

Bases: object

Base class for all the Variational Quantum Simulation Methods.

This implementation is based on work in Quantum 3, 191 (2019).

Parameters:
  • integrator (GeneralIntegrator) – An integrator to solve linear equations.

  • expressions (ComputableNode) – A computable expression whose evaluate() returns a matrix \(A\) and vector \(b\) as \((A, b)\) for the linear problem \(A * x = b\).

  • initial_parameters (SymbolDict) – Initial parameters for the time evolution.

build(protocol)

Executes the build method of a computable expression.

Parameters:
  • backend – Backend for the computable protocols.

  • protocol (EvaluatorRunnerMixin) – Protocol to build computable with.

Returns:

AlgorithmVQS – self.

property final_parameters: SymbolDict

Parameters used to evaluate final expectation value.

final_propagation_evaluation(runner)

Evaluates input computable expression for the last step of the propagation.

Parameters:
  • runner (Callable[[SymbolDict], Any]) – Computable expression to be evaluated.

  • **kwargs – Keyword arguments to be passed to computable run() method.

Returns:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]] – Evaluated computable expression for the last step of the propagation.

post_propagation_evaluation(runner, *args, **kwargs)

Evaluates input computable expression along propagation trajectory.

This is done after propagation has been done.

Parameters:
  • runner (Callable[[SymbolDict], Any]) – Computable expression to be evaluated along propagation trajectory.

  • *args – Arguments to be passed to computable run() method.

  • **kwargs – Keyword arguments to be passed to computable run() method.

Returns:

list[ndarray] – A list of evaluated computable expressions for each time step of the propagation.

run(**kwargs)

Performs the ODE experiment.

Parameters:

**kwargs – Passed to the underlying computable run.

Returns:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]] – The solution to the ODE experiment.

Raises:

RuntimeError – If member variable _backend is not initialised.

class AlgorithmMcLachlanRealTime(integrator, hamiltonian, ansatz, initial_parameters)

Bases: AlgorithmVQS

Algorithm for real time evolution with McLachlan’s variational principle.

Based on work in Quantum 3, 191 (2019).

Parameters:
  • integrator (GeneralIntegrator) – An integrator to solve linear equations.

  • hamiltonian (QubitOperator) – Hamiltonian under which to time evolve.

  • ansatz (GeneralAnsatz) – Wavefunction ansatz to time evolve.

  • initial_parameters (SymbolDict) – Initial parameters for time evolution.

Notes

The same protocol is used in build() method to build the metric tensor, MetricTensorReal, and the derivative, ExpectationValueBraDerivativeReal.

build(protocol)

Executes the build method of a computable expression.

Parameters:
  • backend – Backend for the computable protocols.

  • protocol (EvaluatorRunnerMixin) – Protocol to build computable with.

Returns:

AlgorithmVQS – self.

property final_parameters: SymbolDict

Parameters used to evaluate final expectation value.

final_propagation_evaluation(runner)

Evaluates input computable expression for the last step of the propagation.

Parameters:
  • runner (Callable[[SymbolDict], Any]) – Computable expression to be evaluated.

  • **kwargs – Keyword arguments to be passed to computable run() method.

Returns:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]] – Evaluated computable expression for the last step of the propagation.

post_propagation_evaluation(runner, *args, **kwargs)

Evaluates input computable expression along propagation trajectory.

This is done after propagation has been done.

Parameters:
  • runner (Callable[[SymbolDict], Any]) – Computable expression to be evaluated along propagation trajectory.

  • *args – Arguments to be passed to computable run() method.

  • **kwargs – Keyword arguments to be passed to computable run() method.

Returns:

list[ndarray] – A list of evaluated computable expressions for each time step of the propagation.

run(**kwargs)

Performs the ODE experiment.

Parameters:

**kwargs – Passed to the underlying computable run.

Returns:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]] – The solution to the ODE experiment.

Raises:

RuntimeError – If member variable _backend is not initialised.

class AlgorithmMcLachlanImagTime(integrator, hamiltonian, ansatz, initial_parameters)

Bases: AlgorithmVQS

Algorithm for imaginary time evolution with McLachlan’s variational principle.

Based on work in Quantum 3, 191 (2019).

Parameters:
  • integrator (GeneralIntegrator) – An integrator to solve linear equations.

  • hamiltonian (QubitOperator) – Hamiltonian under which to time evolve.

  • ansatz (GeneralAnsatz) – Wavefunction ansatz to time evolve.

  • initial_parameters (SymbolDict) – Initial parameters for time evolution.

Notes

Note that the same protocol is used in build() method to build the metric tensor, MetricTensorImag, and the derivative, ExpectationValueBraDerivativeImag.

build(protocol)

Executes the build method of a computable expression.

Parameters:
  • backend – Backend for the computable protocols.

  • protocol (EvaluatorRunnerMixin) – Protocol to build computable with.

Returns:

AlgorithmVQS – self.

property final_parameters: SymbolDict

Parameters used to evaluate final expectation value.

final_propagation_evaluation(runner)

Evaluates input computable expression for the last step of the propagation.

Parameters:
  • runner (Callable[[SymbolDict], Any]) – Computable expression to be evaluated.

  • **kwargs – Keyword arguments to be passed to computable run() method.

Returns:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]] – Evaluated computable expression for the last step of the propagation.

post_propagation_evaluation(runner, *args, **kwargs)

Evaluates input computable expression along propagation trajectory.

This is done after propagation has been done.

Parameters:
  • runner (Callable[[SymbolDict], Any]) – Computable expression to be evaluated along propagation trajectory.

  • *args – Arguments to be passed to computable run() method.

  • **kwargs – Keyword arguments to be passed to computable run() method.

Returns:

list[ndarray] – A list of evaluated computable expressions for each time step of the propagation.

run(**kwargs)

Performs the ODE experiment.

Parameters:

**kwargs – Passed to the underlying computable run.

Returns:

ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]] – The solution to the ODE experiment.

Raises:

RuntimeError – If member variable _backend is not initialised.