ClassicalSimState#

qualtran.simulation.classical_sim.ClassicalSimState

A mutable class for classically simulating composite bloqs.

Consider using the public method Bloq.call_classically(…) for a simple interface for classical simulation.

The .step() and .finalize() methods provide fine-grained control over the progress of the simulation; or the .simulate() method will step through the entire composite bloq.

signature

The signature of the composite bloq.

binst_graph

The directed-graph form of the composite bloq. Consider constructing this class with the .from_cbloq constructor method to correctly generate the binst graph.

vals

A mapping of input register name to classical value to serve as inputs to the procedure.

random_handler

The classical random number handler to use for use in measurement-based outcomes (e.g. MBUC).

soq_assign

An assignment of soquets to classical values. We store the classical state of each soquet (wire connection point in the compute graph) for debugging and/or visualization. After stepping through each bloq instance, the right-dangling soquet are assigned the output classical values

last_binst

A record of the last bloq instance we processed during simulation. This can be used in concert with .step() for debugging.

Methods#

from_cbloq

View source

Initiate a classical simulation from a CompositeBloq.

Args

cbloq

The composite bloq

vals

A mapping of input register name to classical value to serve as inputs to the procedure.

Returns

step

View source

Advance the simulation by one bloq instance.

After calling this method, self.last_binst will contain the bloq instance that was just simulated. self.soq_assign and any other state variables will be updated.

Returns

finalize

View source

Finish simulating a composite bloq and extract final values.

Returns

final_vals

The final classical values, keyed by the RIGHT register names of the composite bloq.

Raises

simulate

View source

Simulate the composite bloq and return the final values.