qrunch.quantum.algorithms.second_quantization.quantum_selected_configuration_interaction.run_summary

Progress callback and run summary of quantum-selected configuration interaction.

Classes

SamplingProgressCallback

Protocol for a callback that is called after every circuit sampled by a QSCI run.

SamplingRunSummary

Summary of the sampling in a QSCI run.

class SamplingProgressCallback

Bases: Protocol

Protocol for a callback that is called after every circuit sampled by a QSCI run.

__init__(*args, **kwargs)
record_circuit_sampled(*, number_of_circuits: int, number_of_shots: int, number_of_kept_shots: int, number_of_determinants: int, number_of_determinants_outside_reference_sector: int) → None

Report progress after a circuit is sampled.

Parameters:
  • number_of_circuits (int) – Number of circuits sampled so far.

  • number_of_shots (int) – Number of shots requested so far.

  • number_of_kept_shots (int) – Number of shots kept so far after error mitigation.

  • number_of_determinants (int) – Number of determinants in the current subspace.

  • number_of_determinants_outside_reference_sector (int) – Number of distinct sampled determinants whose numbers of alpha and beta electrons differ from those of every reference determinant.

Return type:

None

class SamplingRunRecorder

Bases: object

Accumulate the circuits and shots of a QSCI run into a SamplingRunSummary.

__init__(reference_determinants: Iterable[int], number_of_qubits: int, *, is_hardcore_bosonic: bool, callback: SamplingProgressCallback | None = None) → None

Initialize an empty record.

Parameters:
  • reference_determinants (Iterable[int]) – Determinants defining the reference particle sectors, as bitstring integers.

  • number_of_qubits (int) – Number of qubits of the Hamiltonian; alpha spin-orbitals come before beta ones.

  • is_hardcore_bosonic (bool) – Whether every qubit holds an electron pair rather than a single electron.

  • callback (SamplingProgressCallback | None) – An optional callback given the sampling metrics after every recorded measurement.

Return type:

None

property number_of_circuits: int

Number of circuits sampled so far.

record_measurement(measurement: QuantumMeasurement, shots: int, number_of_determinants: int) → None

Record the measurement of a sampled circuit and report the metrics so far to the callback, if any.

Parameters:
  • measurement (QuantumMeasurement) – The measurement, after error mitigation.

  • shots (int) – Number of shots requested for the circuit.

  • number_of_determinants (int) – Number of determinants in the subspace, the measured ones included.

Return type:

None

summary(number_of_determinants: int) → SamplingRunSummary

Summarize the run so far.

Parameters:

number_of_determinants (int) – Number of determinants in the subspace.

Return type:

SamplingRunSummary

class SamplingRunSummary

Bases: object

Summary of the sampling in a QSCI run.

All fields are immutable (frozen=True) so an instance can be safely reused.

Parameters:
  • number_of_circuits – Number of circuits sampled.

  • number_of_shots – Number of shots requested over all circuits.

  • number_of_kept_shots – Number of shots kept after error mitigation, e.g. post-selection.

  • number_of_determinants – Number of determinants in the subspace.

  • number_of_determinants_outside_reference_sector – Number of distinct sampled determinants whose numbers of alpha and beta electrons differ from those of every reference determinant.

__init__(number_of_circuits: int, number_of_shots: int, number_of_kept_shots: int, number_of_determinants: int, number_of_determinants_outside_reference_sector: int) → None
Parameters:
  • number_of_circuits (int)

  • number_of_shots (int)

  • number_of_kept_shots (int)

  • number_of_determinants (int)

  • number_of_determinants_outside_reference_sector (int)

Return type:

None

number_of_circuits: int
number_of_determinants: int
number_of_determinants_outside_reference_sector: int
number_of_kept_shots: int
number_of_shots: int
class SubspaceUpdateCallback

Bases: SamplingProgressCallback, Protocol

Protocol for a callback of the adaptive QSCI, also called after every update of its sampling strategy.

It is called after every sampled circuit as well, see SamplingProgressCallback.

__init__(*args, **kwargs)
record_circuit_sampled(*, number_of_circuits: int, number_of_shots: int, number_of_kept_shots: int, number_of_determinants: int, number_of_determinants_outside_reference_sector: int) → None

Report progress after a circuit is sampled.

Parameters:
  • number_of_circuits (int) – Number of circuits sampled so far.

  • number_of_shots (int) – Number of shots requested so far.

  • number_of_kept_shots (int) – Number of shots kept so far after error mitigation.

  • number_of_determinants (int) – Number of determinants in the current subspace.

  • number_of_determinants_outside_reference_sector (int) – Number of distinct sampled determinants whose numbers of alpha and beta electrons differ from those of every reference determinant.

Return type:

None

record_subspace_update(update_index: int, number_of_circuits_sampled: int, subspace_size_before_update: int, subspace_size_after_update: int, energy: float) → None

Report progress after an update of the sampling strategy.

Note that the update_index integer starts at 0 and is incremented with 1 each update.

Parameters:
  • update_index (int) – Index of the update.

  • number_of_circuits_sampled (int) – Number of circuits sampled before the update.

  • subspace_size_before_update (int) – Number of determinants in the subspace before the update.

  • subspace_size_after_update (int) – Number of determinants kept by the update. Pruning and the natural-orbital transformation may leave out determinants.

  • energy (float) – Lowest eigenvalue of the Hamiltonian in the subspace kept by the update.

Return type:

None