Skip to content

Timing

The object that holds information about an algorithm's runtime.

This class can only be constructed using a Timer. This ensures that a Timing object always contains a start as well as an end time.

The qpu field of this class can only be set after constructing it with a timer.

Examples:

>>> from dwave.samplers.tree.solve import BinaryQuadraticModel
>>> from luna_quantum import Model, Timer, Timing
>>> model = ... # third-party model
>>> algorithm = ... # third-party algorithm
>>> timer = Timer.start()
>>> sol = algorithm.run(model)
>>> timing: Timing = timer.stop()
>>> timing.qpu = sol.qpu_time
>>> timing.total_seconds
1.2999193
>>> timing.qpu
0.02491934

end property

end: datetime

The end, or finishing, time of the algorithm.

qpu property writable

qpu: float | None

The qpu usage time of the algorithm this timing object was created for.

start property

start: datetime

The starting time of the algorithm.

total property

total: timedelta

The difference of the end and start time.

Raises:

Type Description
RuntimeError

If total cannot be computed due to an inconsistent start or end time.

total_seconds property

total_seconds: float

The total time in seconds an algorithm needed to run. Computed as the difference of end and start time.

Raises:

Type Description
RuntimeError

If total_seconds cannot be computed due to an inconsistent start or end time.

add_qpu

add_qpu(value: float)

Add qpu usage time to the qpu usage time already present. If the current value is None, this method acts like a setter.

Parameters:

Name Type Description Default
value float

The value to add to the already present qpu value.

required

Raises:

Type Description
ValueError

If value is negative.