core
Observer ¶
Base class for observers which are used to monitor and record the state of the simulation at specified intervals.
Parameters:
-
interval
(int
, default:1
) –The interval at which the observer will be called, by default 1.
Attributes:
-
interval
(int
) –The interval at which the observer will be called.
Source code in quansino/io/core.py
__call__
abstractmethod
¶
Call the observer with the given arguments. This method should be overridden by subclasses to implement specific behavior.
Parameters:
-
*args
(Any
, default:()
) –Positional arguments passed to the observer.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to the observer.
Source code in quansino/io/core.py
attach_simulation
abstractmethod
¶
Attach a simulation to the observer. This method should be overridden by subclasses to implement specific attachment behavior.
Parameters:
-
*args
(Any
, default:()
) –Positional arguments passed to the observer.
-
**kwargs
(Any
, default:{}
) –Keyword arguments passed to the observer.
Source code in quansino/io/core.py
to_dict ¶
Convert the Observer
object to a dictionary.
Returns:
Source code in quansino/io/core.py
TextObserver ¶
Bases: Observer
Base class for text-based observers in a simulation. TextObservers
are used to write output to a file or stream at specified intervals.
Parameters:
-
file
(IO | Path | str
) –The file or stream to write output to. This can be a file object, a string representing a file path, or a
Path
object. -
interval
(int
, default:1
) –The interval at which the observer will be called, by default 1.
-
mode
(str
, default:'a'
) –The mode in which to open the file, by default "a".
-
encoding
(str | None
, default:None
) –The encoding to use when opening the file, by default None. If None, default to 'utf-8' for text files stays None for binary files.
Attributes:
-
accept_stream
(bool
) –Whether the observer accepts a stream of data.
-
file
(IO
) –The file or stream to write output to.
-
mode
(str
) –The mode in which to open the file.
-
encoding
(str | None
) –The encoding to use when opening the file.
Source code in quansino/io/core.py
file
property
writable
¶
Get the file object associated with the TextObserver
.
Returns:
-
IO
–The file object associated with the
TextObserver
.
__repr__ ¶
Return a representation of the TextObserver
.
Returns:
-
str
–The representation of the
TextObserver
.
Source code in quansino/io/core.py
__str__ ¶
Return a string representation of the TextObserver
.
Returns:
-
str
–The string representation of the
TextObserver
, including the file type and name.
Source code in quansino/io/core.py
attach_simulation ¶
Attach the simulation to the Observer
via a FileManager
.
Parameters:
-
file_manager
(FileManager
) –The
FileManager
instance to attach to the observer.
Source code in quansino/io/core.py
close ¶
Close the file if it is not a standard stream.
Source code in quansino/io/core.py
to_dict ¶
Convert the TextObserver
object to a dictionary.
Returns: