ClassicalSimState#
qualtran.simulation.classical_sim.ClassicalSimState
View source on GitHub
|
A mutable class for classically simulating composite bloqs.
qualtran.simulation.classical_sim.ClassicalSimState(
signature: 'Signature',
binst_graph: nx.DiGraph,
vals: Mapping[str, Union[sympy.Symbol, ClassicalValT]],
random_handler: '_ClassicalValHandler' = _BannedClassicalValHandler()
)
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.
Args
signatureThe signature of the composite bloq.
binst_graphThe directed-graph form of the composite bloq. Consider constructing this class with the
.from_cbloqconstructor method to correctly generate the binst graph.valsA mapping of input register name to classical value to serve as inputs to the procedure.
random_handlerThe classical random number handler to use for use in measurement-based outcomes (e.g. MBUC).
Attributes
soq_assignAn 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_binstA record of the last bloq instance we processed during simulation. This can be used in concert with
.step()for debugging.
Methods#
from_cbloq
@classmethodfrom_cbloq( cbloq: 'CompositeBloq', vals: Mapping[str, Union[sympy.Symbol, ClassicalValT]] ) -> 'ClassicalSimState'
Initiate a classical simulation from a CompositeBloq.
Args
cbloqThe composite bloq
valsA mapping of input register name to classical value to serve as inputs to the procedure.
Returns
step
step() -> 'ClassicalSimState'
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
finalize() -> Dict[str, 'ClassicalValT']
Finish simulating a composite bloq and extract final values.
Returns
final_valsThe final classical values, keyed by the RIGHT register names of the composite bloq.
Raises
simulate
simulate() -> Dict[str, 'ClassicalValT']
Simulate the composite bloq and return the final values.
View source on GitHub