pyquibbler.Quib
- class pyquibbler.Quib(quib_function_call: QuibFuncCall = None, assignment_template: AssignmentTemplate | None = None, allow_overriding: bool = False, assigned_name: str | None = None, created_in: FileAndLineNumber | None = None, graphics_update: GraphicsUpdateType | None = None, save_directory: pathlib.Path | None = None, save_format: SaveFormat | None = None, func: Callable | None = None, args: Args = (), kwargs: Kwargs = None, func_definition: FuncDefinition = None, cache_mode: CacheMode = None)
Bases:
object
A Quib represents the output of a call to a specific function with specific arguments.
Function
The function run by the quib.
The positional arguments to be passed to the function run by the quib.
The keyworded arguments for the function run by the quib.
Indicates whether the quib is an input quib (iquib).
Specifies whether the function runs by the quib is a graphics function.
Indicates whether the quib represents a random function.
Indicates whether the quib represents a function that loads external files.
Indicates whether the quib runs an impure function.
Indicates whether the quib passes quib arguments to its function.
Calculate
Calculate the entire value of the quib.
Invalidate the quib value.
get_ndim
()Return the number of dimensions of the quib's value.
Return the shape of the quib's value.
get_type
()Return the type of the quib's value.
The caching mode for the quib.
The status of the quib's cache.
Relationships
get_children
([bypass_intermediate_quibs])Return the set of quibs that are immediately downstream of the current quib.
get_parents
([bypass_intermediate_quibs, ...])Return the set of quibs immediate upstream to the current quib.
get_descendants
([bypass_intermediate_quibs, ...])Search for all quibs downstream of current quib.
get_ancestors
([bypass_intermediate_quibs, depth])Search for all upstream quibs that this quib depends on.
Assignments
Indicates whether the quib's value can be overridden.
Specifies the quibs to which assignments to this quib could inverse-translate to.
Dictates type and range restricting assignments to the quib.
set_assignment_template
(*args)Sets an assignment template for the quib.
assign
(value, *keys)Assign a value to the whole quib, or to a specific key.
Return an Overrider object representing a list of overrides performed on the quib.
Create a new quib whose value is the override mask of the current quib.
File sync
The project object that the quib belongs to.
The directory where quib assignments are saved.
The actual directory where quib file is saved.
The file format in which quib overriding assignments are saved.
The actual save_format used by the quib.
The full path for the file where quib assignments are saved.
load
([response_to_file_not_defined, ...])Load quib assignments from the quib's file.
save
([response_to_file_not_defined, ...])Save the quib assignments to the quib's file.
sync
([response_to_file_not_defined])Sync quib assignments with the quib's file.
Name and display
The name of the quib.
The assigned_name of the quib.
get_quiby_name
([as_repr])Create a new quib representing the name of the current quib.
The file and line number where the quib was created.
A string representing the function and arguments of the quib.
a pretty string representation of the quib.
a simple string representation of the quib.
display
()Display the quib as a QuibWidget.
Returns a QuibPropertiesViewer which displays the properties of the quib.
Graphics
Specifies when the quib should re-evaluate and refresh graphics.
The actual graphics update mode of the quib.
Specifies whether the quib is a graphics quib.
Other
iter_first
([amount])Return an iterator to the first amount elements of the quib.
setp
([allow_overriding, ...])Set one or more properties on a quib.
- property func: Callable
The function run by the quib.
A quib calls its function
func
, with its positional argumentsargs
and its keyworded argumentskwargs
.The quib’s value is given by
value = func(*args, **kwargs)
, with any quibs in args or kwargs replaced by their values (unlesspass_quibs=True
).See also
args
,kwargs
,pass_quibs
,is_pure
,is_random
,is_graphics
Examples
>>> w = iquib(0.5) >>> s = np.sin(w) >>> s.func np.sin
- Type:
Callable
- property args: Tuple[Any, ...]
The positional arguments to be passed to the function run by the quib.
A quib calls its function
func
, with its positional argumentsargs
and its keyworded argumentskwargs
.The quib’s value is given by
value = func(*args, **kwargs)
.args is a tuple of all positional arguments, which could each be any object including quibs. Any quibs in args are replaced with their values when the function is called (unless
pass_quibs=True
).See also
Examples
>>> w = iquib(0.5) >>> s = w + 10 >>> s.args (w, 10)
- Type:
tuple of any
- property kwargs: Dict[str, Any]
The keyworded arguments for the function run by the quib.
A quib calls its function
func
, with its positional argumentsargs
and its keyworded argumentskwargs
.The quib’s value is given by
value = func(*args, **kwargs)
.kwargs is a dictionary of str keywords mapped to any object including non-quib or quib arguments. Any quibs in kwargs are replaced with their values when the function is called (unless
pass_quibs=True
).See also
Examples
>>> a = iquib(10) >>> s = np.linspace(start=0, stop=a) >>> s.kwargs {'start': 0, 'stop': a}
- Type:
dict of str to any
- property is_impure: bool
Indicates whether the quib runs an impure function.
True if the function of the quib is impure, either a random function or a file loading function.
Examples
>>> n = iquib(5) >>> r = np.random.randint(0, n) >>> r.is_impure True
- Type:
bool
- property is_random: bool
Indicates whether the quib represents a random function.
A quib that represents a random function automatically caches its value. Thereby, repeated calls to the quib return the same random cached results (quenched randomization). This behaviour guarentees mathematical consistency (for example, if
r
is a random quibs = r - r
will always give a value of 0).The quib can be re-evaluated (randomized), by invalidating its value either locally using
invalidate()
or centrally, usingqb.reset_random_quibs()
Examples
>>> n = iquib(5) >>> r = np.random.randint(0, n) >>> r.is_random True
- Type:
bool
- property is_file_loading: bool
Indicates whether the quib represents a function that loads external files.
A quib whose value depends on the content of external files automatically caches its value. Thereby, repeated calls to the quib return the same results even if the file changes.
The quib can be re-evaluated, by invalidating its value either locally using
invalidate()
or centrally, usingqb.reset_file_loading_quibs()
Examples
>>> file_name = iquib('my_file.txt') >>> x = np.loadtxt(file_name) >>> x.is_file_loading True
- Type:
bool
- property pass_quibs: bool
Indicates whether the quib passes quib arguments to its function.
Normally, any parent quibs within the args and kwargs of the focal quib are replaced with their values when the quib calls its function (
pass_quibs=False
).Setting
pass_quibs=True
, such quib arguments are passed directly to the quib’s function, as quib objects. Such behavior is important if we need to allow inverse assignments from graphics created in the function.- Type:
bool
- property cache_status: CacheStatus
The status of the quib’s cache.
ALL_INVALID
: the cache is fully invalid, or the quib is not caching.ALL_VALID
: The cache is fully valid.PARTIAL
: Only part of the quib’s cache is valid.See also
- Type:
- property cache_mode: CacheMode
The caching mode for the quib.
Dictates whether the quib should cache its value upon function evaluation.
Can be set as CacheMode or as str:
'auto'
: Caching is decided automatically according to the ratio between evaluation time and memory consumption.'on'
: Always cache.'off'
: Do not cache, unless the quib’s function is random or graphics.See also
Notes
Quibs with random functions and graphics quibs are always cached even when cache mode is
'off'
.- Type:
- invalidate()
Invalidate the quib value.
Invalidate the value of the quib and the value of any downstream dependent quibs. Any downstream graphic quibs will be re-evaluated.
- property is_graphics: bool
Specifies whether the function runs by the quib is a graphics function.
True
: known graphics functionsFalse
: known non-graphics functionsNone
: auto-detect. Used for functions that may create graphics (default for user functions).See also
- Type:
bool or None
- property is_graphics_quib: bool
Specifies whether the quib is a graphics quib.
A quib is defined as a graphics quib if its function is a known graphics function (
is_graphics=True
), or if its function’s is graphics-auto-detect (is_graphics=None
) and a call to the function created graphics.Additionally, quibs with assigned callback functions are also defined as graphics.
A quib defined as a graphics quib will automatically-refreshes upon upstream changes, based on its graphics_update property.
- Type:
bool
- property graphics_update: GraphicsUpdateType | None
Specifies when the quib should re-evaluate and refresh graphics.
Can be set to a GraphicsUpdateType, or str:
'drag'
: Update continuously as upstream quibs are being dragged, or upon programmatic assignments to upstream quibs (default for graphics quibs).'drop'
: Update only at the end of dragging of upstream quibs (at mouse ‘drop’), or upon programmatic assignments to upstream quibs.'central'
: Do not automatically update graphics upon upstream changes. Only update upon explicit request for the quibs get_value(), or upon the central redraw command: refresh_graphics().'never'
: Do not automatically update graphics upon upstream changes. Only update upon explicit request for the quibs get_value().None
: Yield to the default project’s graphics_updateSee also
actual_graphics_update
,GraphicsUpdateType
,Project.graphics_update
,pyquibbler.refresh_graphics
- Type:
GraphicsUpdateType or None
- property actual_graphics_update
The actual graphics update mode of the quib.
The quib’s
actual_graphics_update
is specified by itsgraphics_update
if notNone
. Otherwise, it defaults to the project’sgraphics_update
.See also
- property allow_overriding: bool
Indicates whether the quib’s value can be overridden.
The default for allow_overriding is True for input quibs (iquibs) and False in function quibs (fquibs).
See also
- Type:
bool
- assign(value: Any, *keys) None
Assign a value to the whole quib, or to a specific key.
Assuming
w
is a quib:w.assign(value)
assigns a new value to the quib as a whole.w.assign(value, key)
assigns the quib at the specified key. This is equivalent tow[key] = value
.w.assign(value, key1, key2, ..., keyN)
assigns the quib at the specified path of keys. Equivalent tow[key1][key2]...[kenN] = value
.- Parameters:
value (any) – A value to assign as to the quib at the specified key.
keys (any (optional)) – An optional list of arguments representing the keys into which to assign the value.
See also
Inverse-assignments
,get_value
,assigned_quibs
,allow_overriding
,get_override_list
Examples
Whole-object assignment:
>>> a = iquib([1, 2, 3]) >>> a.assign('new value') >>> a.get_value() 'new value'
Item-specific assignment:
>>> a = iquib([1, 2, 3]) >>> a.assign('new value', 1) >>> a.get_value() [1, 'new value', 3]
Note
Assigned values can override the value of the focal quib, or can inverse propagate to override the values of upstream quibs. The level at which the assignment is actulaized is controlled by the assigned_quibs property of the focal quib to which the assignment is made and by the allow_overriding property of upstream quibs.
- property assigned_quibs: None | Set[Quib, ...]
Specifies the quibs to which assignments to this quib could inverse-translate to.
Options:
- set of Quibs :
Assignments to the quib can be actualized as overrides at any upstream quibs included in the specified set and whose
allow_overriding=True
.
Quib : Specifying a single quib, instead of a set, is interpreted as a set containing this single quib.
- set() :
Prevents assignments to this quib.
- ‘self’ :
To allow assignments to actualize locally, as overrides of the focal quib to which the assignments are made, the focal quib itself, or ‘self’, can be used alone or as part of the set of quibs. When self is included, the
allow_overriding
property is automatically set toTrue
.- None(default)
Assignments to the quib can be actualized as overrides at any upstream quib whose
allow_overriding=True
. If while inverting the assignment an upstream quib is encountered with defined assigned_quibs (not None), the set it defines is used for choosing upstream quibs for assignments.
If multiple choices are available for inverse assignment, a dialog is presented to allow choosing between these options.
See also
- Type:
None or set of Quib
- property assignment_template: AssignmentTemplate | None
Dictates type and range restricting assignments to the quib.
See also
- Type:
AssignmentTemplate or None
- set_assignment_template(*args) Quib
Sets an assignment template for the quib.
The assignment template restricts the values of overriding assignments to the quib.
Options:
- Set a specific AssignmentTemplate object:
set_assignment_template(assignment_template)
- Set a bound template between start and stop:
set_assignment_template(start, stop)
- Set a bound template between start and stop, with specified step:
quib.set_assignment_template(start, stop, step)
- Remove the assignment_template:
set_assignment_template(None)
- Returns:
quib – The focal quib.
- Return type:
See also
Examples
>>> a = iquib(20) >>> a.set_assignment_template(0, 100, 10) # restrict to 0, 10, ..., 100 >>> a.assign(37) >>> a.get_value() 40 >>> a.assign(170) >>> a.get_value() 100
Note
Setting the assignment_template only affects future overrides to the quib. It does not alter exisitng overrides.
- setp(allow_overriding: bool = missing, assignment_template: None | tuple | AssignmentTemplate = missing, save_directory: None | str | Path = missing, save_format: None | str | SaveFormat = missing, cache_mode: str | CacheMode = missing, assigned_name: None | str = missing, name: None | str = missing, graphics_update: None | str = missing, assigned_quibs: Set[Quib] | None = missing) Quib
Set one or more properties on a quib.
- Parameters:
allow_overriding (bool, optional) – Specifies whether the quib is open for overriding assignments.
assigned_quibs (None, Set[Quib], or 'self', optional) – Indicates which upstream quibs to inverse-assign to.
assignment_template (tuple or AssignmentTemplate, optional) – Constrain the type and value of overriding assignments to the quib.
save_directory (str or pathlib.Path, optional) – The directory to which quib assignments are saved.
save_format ({None, 'off', 'txt', 'bin'} or SaveFormat, optional) – The file format for saving quib assignments.
cache_mode ({'auto', 'on', 'off'} or CacheMode, optional) – Indicates whether the quib caches its calculated value.
assigned_name (None or str, optional) – The user-assigned name of the quib.
name (None or str, optional) – The name of the quib.
graphics_update ({None, 'drag', 'drop', 'central', 'never'} or GraphicsUpdateType, optional) – For graphics quibs, indicates when they should be refreshed.
- Returns:
quib – The focal quib.
- Return type:
See also
allow_overriding
,assigned_quibs
,assignment_template
,save_directory
,save_format
,cache_mode
,assigned_name
,name
,graphics_update
- Examples
>>> a = iquib(7) >>> b = (2 * a).setp(allow_overriding=True, assigned_name='two_times_a')
- add_callback(callback: Callable)
Add a function to call when the quib value changes.
The callback function will be called when the quib value changes, with the new value of the quib as an argument. The callback is executed upon drag, drop or centrally, as specified by the quib’s graphics_update.
- Parameters:
callback (Callable) – The function to call upon a change to the quib value. The function is called as
callback(new_value)
See also
is_graphics
,graphics_update
,remove_callback
,get_callbacks
- remove_callback(callback: Callable)
Remove a function from the callback set.
Remove a function that was added to the quib callbacks.
- Parameters:
callback (Callable) – The function to remove
See also
- get_callbacks() Set[Callable]
Return the set of callback functions.
Return the set of functions that the quib calls upon value change.
- Returns:
The set of callback functions
- Return type:
Set of Callable
See also
- get_value_valid_at_path(path: None | List[PathComponent] | List[Any]) Any
Get the value of the quib, calculated only for a requested path.
value = quib.get_value_valid_at_path([c0, c1, ..., cN])
returnsvalue
which has the same shape as the real value of the quib (quib.get_value()
), but with data that is only guaranteed to be correct at the specified path. Namely,value
is only guanteed to be valid atvalue[c0][c1]...[cmpN]
.This can save calculations of heavy to calculate arrays, allowing to calculate only part of the array.
- Parameters:
path (list of components, or None) –
path=[c0, c1, ..., cN]
: indicates requesting a returned value valid at the indicated path.Namely, the returned
value
will be valid at ``value[c0][c1]…[cN].
None
: indicates requesting a value with the correct shape and type, but where none of the data elements may be valid.[]
: indicates requesting a fully valid value.- Returns:
value – a value with the same shape as the real value of the quib, but guaranteed to be valid only at the specified path.
- Return type:
any
See also
Examples
>>> def square(x): >>> print(f'Calculating square of {x}') >>> return x**2
>>> a = iquib([0, 1, 2, 3]) >>> a_sqr = np.vectorize(square, otypes=(int,))(a) >>> a_sqr.get_value_valid_at_path([2]) # requesting value valid at a_sqr[2] Calculating square of 2 array([2, 2, 4, 2])
Note
As a simpler alternative to
quib.get_value_valid_at_path([c1, c2, ..., cN])[c0][c1]...[cN]
, you can also use the more natual syntaxquib[c0][c1]...[cN].get_value()
, which similarly will only calculate the requested part of the array.
- get_value() Any
Calculate the entire value of the quib.
Run the function of the quib and return the result, or return the value from the cache if valid.
- Returns:
The result of the function of the quib.
- Return type:
any
Examples
>>> a = iquib(3) >>> b = a ** 2 # lazy evaluation >>> b.get_value() # the calculation only occurs when the quib value is requested 9
- get_type() Type
Return the type of the quib’s value.
Implement
type
of the value of the quib.- Returns:
The type of the quib’s value.
- Return type:
type
Notes
Calculating the type of a quib does not necessarily require calculating its entire value.
- get_shape() Tuple[int, ...]
Return the shape of the quib’s value.
Implement
np.shape
of the value of the quib.- Returns:
The shape of the quib’s value.
- Return type:
tuple of int
Notes
Calculating the shape of a quib does not necessarily require calculating its entire value.
- get_ndim() int
Return the number of dimensions of the quib’s value.
Implement
np.ndim
of the value of the quib.- Returns:
the number of dimensions of the quib’s value.
- Return type:
int
Notes
Calculating ndim of a quib does not necessarily require calculating its entire value.
- iter_first(amount: int | None = None)
Return an iterator to the first amount elements of the quib.
a, b = quib.iter_first(2)
is the same asa, b = quib[0], quib[1]
.When
amount=None
, quibbler will try to detect the correct amount automatically, and might fail with a RuntimeError. For example,a, b = iquib([1, 2]).iter_first()
is the same asa, b = iquib([1, 2]).iter_first(2)
. And even if the quib is larger than the unpacked amount, the iterator will still yield only the first items -a, b = iquib([1, 2, 3, 4]).iter_first()
is the same asa, b = iquib([1, 2, 3, 4]).iter_first(2)
.- Return type:
Iterator of Quib
Examples
>>> @quiby ... def sum_and_prod(x): ... return np.sum(x), np.prod(x) ... >>> nums = iquib([10, 20, 30]) >>> sum_nums, prod_nums = sum_and_prod(nums).iter_first() >>> sum_nums.get_value() 60
>>> prod_nums.get_value() 6000
- get_override_list() Overrider | None
Return an Overrider object representing a list of overrides performed on the quib.
- Returns:
an object holding a list of all the assignments to the quib. None if quib is not overridden
- Return type:
Overrider or None
See also
- get_override_mask()
Create a new quib whose value is the override mask of the current quib.
Assuming this quib represents a numpy ndarray, return a quib representing its override mask.
The override mask is a boolean array of the same shape, in which every value is set to True if the matching value in the array is overridden, and False otherwise.
- Returns:
A quib representing the override mask of the current quib.
- Return type:
See also
- get_children(bypass_intermediate_quibs: bool = False) Set[Quib]
Return the set of quibs that are immediately downstream of the current quib.
- Parameters:
bypass_intermediate_quibs (bool, default: False) – Indicates whether to bypass intermediate quibs. Intermediate quibs are defined as unnamed and non-graphics quibs (
assigned_name=None
andis_graphics=False
), typically representing intermediate calculations.- Returns:
The set of child quibs
- Return type:
Set of Quib
See also
get_ancestors
,get_parents
,get_descendants
,dependency_graph
Examples
>>> a = iquib(1) >>> b = a + 1 >>> c = (a + 2) * b >>> a.get_children() {b = a + 1, a + 2} >>> a.get_children(True) {b = a + 1, c = (a + 2) * b}
- get_descendants(bypass_intermediate_quibs: bool = False, depth: int | None = None) Set[Quib]
Search for all quibs downstream of current quib.
Recursively search downstream to find all the quibs that depend on the current quib.
- Parameters:
bypass_intermediate_quibs (bool, default: False) – Indicates whether to bypass intermediate quibs. Intermediate quibs are defined as unnamed and non-graphics quibs (
assigned_name=None
andis_graphics=False
), typically representing intermediate calculations.depth (int or None) – Depth of search, 0 returns empty set, 1 returns the children, etc. None for infinite (default).
- Returns:
The set of descendant quibs
- Return type:
Set of Quib
See also
Examples
>>> a = iquib(1) >>> b = a + 1 >>> c = (a + 2) * b >>> d = b * (c + 1) >>> a.get_descendants() {b = a + 1, a + 2, c = (a + 2) * b, c + 1, d = b * (c + 1)} >>> a.get_descendants(True) {b = a + 1, c = (a + 2) * b, d = b * (c + 1)}
- get_parents(bypass_intermediate_quibs: bool = False, is_data_source: bool | None = None) Set[Quib]
Return the set of quibs immediate upstream to the current quib.
The parents are the immediate quibs that this quib depends on, namely the quibs in the args and kwargs of the quib function call.
- Parameters:
bypass_intermediate_quibs (bool, default: False) – Indicates whether to bypass intermediate quibs. Intermediate quibs are defined as unnamed and non-graphics quibs (
assigned_name=None
andis_graphics=False
), typically representing intermediate calculations.is_data_source (bool or None. default: None) – Include only data sources (True), only paramter sources (False), or both (None, default).
- Returns:
The set of parent quibs
- Return type:
Set of Quib
See also
args
,kwargs
,get_ancestors
,get_children
,get_descendants
,dependency_graph
Examples
>>> a = iquib(1) >>> b = iquib(3) >>> c = (a + 2) * b >>> c.get_parents() {a + 2, b = iquib(3)} >>> c.get_parents(True) {a = iquib(1), b = iquib(3)}
- get_ancestors(bypass_intermediate_quibs: bool = False, depth: int | None = None) Set[Quib]
Search for all upstream quibs that this quib depends on.
Recursively scan upstream to find all the quibs that this quib depends on.
- Parameters:
bypass_intermediate_quibs (bool, default: False) – Indicates whether to bypass intermediate quibs. Intermediate quibs are defined as unnamed and non-graphics quibs (
assigned_name=None
andis_graphics=False
), typically representing intermediate calculations.depth (int or None) – Depth of search, 0 returns empty set, 1 returns the parents, etc. None for infinite (default).
- Returns:
The set of ancestor quibs
- Return type:
Set of Quib
See also
get_parents
,get_children
,get_descendants
,dependency_graph
Examples
>>> a = iquib(1) >>> b = iquib(3) >>> c = (a + 2) * b >>> c.get_ancestors() {a = iquib(1), a + 2, b = iquib(3)} >>> c.get_ancestors(True) {a = iquib(1), b = iquib(3)}
- property project: Project
The project object that the quib belongs to.
The Project provides global functionality inclduing save, load, sync of all quibs, undo, redo, and randomization of random quibs.
See also
- Type:
- property save_format: SaveFormat
The file format in which quib overriding assignments are saved.
Can be set as SaveFormat or as str, or None:
'txt'
- save overriding assignments as text file (extension ‘.txt’).'bin'
- save overriding assignments as a binary file (extension ‘.quib’).'off'
- do not save overriding assignments of this quib.None
- yield to the Project save_format (default).See also
SaveFormat
,actual_save_format
,Project.SaveFormat
- Type:
- property actual_save_format: SaveFormat
The actual save_format used by the quib.
The quib’s
actual_save_format
is its save_format if defined. Otherwise, it defaults to the project’ssave_format
.See also
- Type:
- property file_path: PathWithHyperLink | None
The full path for the file where quib assignments are saved.
The path is defined as the [actual_save_directory]/[assigned_name].ext
ext is determined by the actual_save_format
See also
save_directory
,actual_save_directory
,save_format
,actual_save_format
,SaveFormat
,assigned_name
,Project.directory
- Type:
pathlib.Path or None
- property save_directory: PathWithHyperLink
The directory where quib assignments are saved.
Can be set to a str or Path objects.
Options:
absolute file path : The quib’s file will be saved at the specified path.
relative file path : The quib’s file will be saved at the specified path relative to the project directory.
None (default) : The quib’s file will be saved to the project directory.
See also
- Type:
PathWithHyperLink
- property actual_save_directory: Path | None
The actual directory where quib file is saved.
By default, the quib’s save_directory is None and the actual_save_directory defaults to the project’s save_directory.
Otherwise, if the quib’s save_directory is defined as an absolute path then it is used as is, and if it is defined as a relative path it is used relative to the project’s directory.
See also
- Type:
pathlib.Path or None
- save(response_to_file_not_defined: ResponseToFileNotDefined = ResponseToFileNotDefined.RAISE, skip_user_verification: bool = False)
Save the quib assignments to the quib’s file.
- load(response_to_file_not_defined: ResponseToFileNotDefined = ResponseToFileNotDefined.RAISE, skip_user_verification: bool = False)
Load quib assignments from the quib’s file.
- sync(response_to_file_not_defined: ResponseToFileNotDefined = ResponseToFileNotDefined.RAISE)
Sync quib assignments with the quib’s file.
If the file was changed it will be read to the quib.
If the quib assignments were changed, the file will be updated.
If both changed, a dialog is presented to resolve conflict.
- property assigned_name: str | None
The assigned_name of the quib.
The assigned_name can either be a name automatically created based on the variable name to which the quib was first assigned, or a manually assigned name set by setp or by assigning to assigned_name, or None indicating unnamed quib.
The name must be a string starting with a letter and continuing with an alpha-numeric character. Spaces are also allowed.
See also
Notes
The assigned_name is also used for setting the file name for saving overrides.
Examples
Automatic naming based on quib’s variable name:
>>> data = iquib([1, 2, 3]) >>> data.assigned_name `data`
Manual naming:
>>> data = iquib([1, 2, 3], assigned_name='my data') >>> data.assigned_name `my data`
- Type:
str or None
- property name: str | None
The name of the quib.
The name of the quib is either the assigned_name if not None, or an automated name representing the function of the quib (the functional_representation attribute).
See also
Notes
Assigning into name is equivalent to assigning into assigned_name.
Examples
>>> number = iquib(7) >>> new_number = number + 3 >>> new_number.name `new_number`
>>> new_number.assigned_name = None >>> new_number.name `number + 3`
- Type:
str
- get_quiby_name(as_repr: bool = False) str
Create a new quib representing the name of the current quib.
- Parameters:
as_repr (bool, Default False) – Whether to return just “name” (as_repr=False), or “name = func(…)” (as_repr=True).
- Return type:
See also
Examples
>>> t = iquib(5) >>> y = iquib(7) >>> plt.plot(t, y, 'o') >>> plt.xlabel(x.get_quiby_name()) >>> # This will create a figure with x-axis label 't'
>>> t.name = 'time' # -> the figure x-axis label will immediately change to 'time'
- property functional_representation: str
A string representing the function and arguments of the quib.
Examples
>>> a = iquib(4) >>> b = (a + 10) ** 2 >>> b.functional_representation '(a + 10) ** 2'
- Type:
str
- get_math_expression() MathExpression
Return a MathExpression object providing a string representation of the quib.
- Return type:
MathExpression
See also
- property ugly_repr: str
a simple string representation of the quib.
- Return type:
str
Examples
>>> a = iquib(4) >>> b = np.sin(a) >>> b.ugly_repr "<Quib - <ufunc 'sin'>"
- Type:
str
- property pretty_repr: str
a pretty string representation of the quib.
- Return type:
str
Examples
>>> a = iquib(4) >>> b = (a + 10) ** 2 >>> b.functional_representation 'b = (a + 10) ** 2'
- Type:
str
- display_properties() QuibPropertiesViewer
Returns a QuibPropertiesViewer which displays the properties of the quib.
- Return type:
See also
- property created_in: FileAndLineNumber | None
The file and line number where the quib was created.
Indicates the place where the quib was created.
None if creation place is unknown.
See also
- Type:
FileAndLineNumber or None
- property is_iquib: bool
Indicates whether the quib is an input quib (iquib).
See also
func
,save_format
,quibbler.iquib
Examples
>>> a = iquib(4) >>> b = a + 10 >>> a.is_iquib() True >>> b.is_iquib() False
- Type:
bool
- display()
Display the quib as a QuibWidget.
Display a QuibWidget allowing interactive viewing of the quib value and properties and editing of quib overrides.
See also
display_properties
,QuibWidget
,pretty_repr
,functional_representation
Note
Displaying a quib widget is only supported within Jupyter Lab and with the ipywidgets package installed.
Quibs are automatically displayed as QuibWidgets in Jupyter Lab, if pyquibbler is initialized with initialize_quibbler(show_quibs_as_widgets=True) (default).