API Reference
This reference provides detailed documentation for all EasyScience classes and functions.
Core Variables and Descriptors
Descriptor Base Classes
easyscience.variable.DescriptorBase
Bases: SerializerComponent
This is the base of all variable descriptions for models. It contains all information to describe a single unique property of an object. This description includes a name and value as well as optionally a unit, description and url (for reference material). Also implemented is a callback so that the value can be read/set from a linked library object.
A Descriptor is typically something which describes part of a model and is non-fittable and generally changes the
state of an object.
Source code in src/easyscience/variable/descriptor_base.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
display_name
property
writable
Get a pretty display name.
:return: The pretty display name.
description
property
writable
Get the description of the object.
:return: description of the object.
unique_name
property
writable
Get the unique name of this object.
:return: Unique name of this object
__init__
This is the base of variables for models. It contains all information to describe a single unique property of an object. This description includes a name, description and url (for reference material).
A Descriptor is typically something which describes part of a model and is non-fittable and generally changes
the state of an object.
:param name: Name of this object :param description: A brief summary of what this object is :param url: Lookup url for documentation/information :param display_name: A pretty name for the object :param parent: The object which this descriptor is attached to
.. note:: Undo/Redo functionality is implemented for the attributes name and display name.
Source code in src/easyscience/variable/descriptor_base.py
__repr__
abstractmethod
easyscience.variable.DescriptorNumber
Bases: DescriptorBase
A Descriptor for Number values with units. The internal representation is a scipp scalar.
Source code in src/easyscience/variable/descriptor_number.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
full_value
property
writable
Get the value of self as a scipp scalar. This is should be usable for most cases.
:return: Value of self with unit.
value
property
writable
Get the value. This should be usable for most cases. The full value can be obtained from obj.full_value.
:return: Value of self with unit.
error
property
writable
The standard deviation for the parameter.
:return: Error associated with parameter
__init__
__init__(
name,
value,
unit='',
variance=None,
unique_name=None,
description=None,
url=None,
display_name=None,
parent=None,
**kwargs,
)
Constructor for the DescriptorNumber class
param name: Name of the descriptor
param value: Value of the descriptor
param unit: Unit of the descriptor
param variance: Variance of the descriptor
param description: Description of the descriptor
param url: URL of the descriptor
param display_name: Display name of the descriptor
param parent: Parent of the descriptor
.. note:: Undo/Redo functionality is implemented for the attributes variance, error, unit and value.
Source code in src/easyscience/variable/descriptor_number.py
from_scipp
classmethod
Create a DescriptorNumber from a scipp constant.
:param name: Name of the descriptor :param value: Value of the descriptor as a scipp scalar :param kwargs: Additional parameters for the descriptor :return: DescriptorNumber
Source code in src/easyscience/variable/descriptor_number.py
_attach_observer
Attach an observer to the descriptor.
Source code in src/easyscience/variable/descriptor_number.py
_detach_observer
Detach an observer from the descriptor.
_notify_observers
_validate_dependencies
Ping all observers to check if any cyclic dependencies have been introduced.
:param origin: Unique_name of the origin of this validation check. Used to avoid cyclic depenencies.
Source code in src/easyscience/variable/descriptor_number.py
_convert_unit
Convert the value from one unit system to another.
:param unit_str: New unit in string form
Source code in src/easyscience/variable/descriptor_number.py
convert_unit
Convert the value from one unit system to another.
:param unit_str: New unit in string form
__copy__
__repr__
Return printable representation.
Source code in src/easyscience/variable/descriptor_number.py
as_dict
Source code in src/easyscience/variable/descriptor_number.py
__add__
Source code in src/easyscience/variable/descriptor_number.py
__radd__
Source code in src/easyscience/variable/descriptor_number.py
__sub__
Source code in src/easyscience/variable/descriptor_number.py
__rsub__
Source code in src/easyscience/variable/descriptor_number.py
__mul__
Source code in src/easyscience/variable/descriptor_number.py
__rmul__
Source code in src/easyscience/variable/descriptor_number.py
__truediv__
Source code in src/easyscience/variable/descriptor_number.py
__rtruediv__
Source code in src/easyscience/variable/descriptor_number.py
__pow__
Source code in src/easyscience/variable/descriptor_number.py
__rpow__
Source code in src/easyscience/variable/descriptor_number.py
__neg__
Source code in src/easyscience/variable/descriptor_number.py
__abs__
Source code in src/easyscience/variable/descriptor_number.py
_base_unit
Extract the base unit from the unit string by removing numeric components and scientific notation.
Source code in src/easyscience/variable/descriptor_number.py
easyscience.variable.DescriptorArray
Bases: DescriptorBase
A Descriptor for Array values with units. The internal representation is a scipp array.
Source code in src/easyscience/variable/descriptor_array.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | |
_array
instance-attribute
full_value
property
writable
Get the value of self as a scipp array. This should be usable for most cases.
:return: Value of self with unit.
value
property
writable
Get the value without units. The Scipp array can be obtained from obj.full_value.
:return: Value of self without unit.
dimensions
property
writable
Get the dimensions used for the underlying scipp array.
:return: dimensions of self.
error
property
writable
The standard deviations, calculated as the square root of variances.
:return: A numpy array of standard deviations, or None if variances are not set.
__init__
__init__(
name,
value,
unit='',
variance=None,
unique_name=None,
description=None,
url=None,
display_name=None,
parent=None,
dimensions=None,
)
Constructor for the DescriptorArray class
param name: Name of the descriptor
param value: List containing the values of the descriptor
param unit: Unit of the descriptor
param variance: Variances of the descriptor
param description: Description of the descriptor
param url: URL of the descriptor
param display_name: Display name of the descriptor
param parent: Parent of the descriptor
param dimensions: List of dimensions to pass to scipp. Will be autogenerated if not supplied.
.. note:: Undo/Redo functionality is implemented for the attributes variance, error, unit and value.
Source code in src/easyscience/variable/descriptor_array.py
from_scipp
classmethod
Create a DescriptorArray from a scipp array.
:param name: Name of the descriptor :param full_value: Value of the descriptor as a scipp variable :param kwargs: Additional parameters for the descriptor :return: DescriptorArray
Source code in src/easyscience/variable/descriptor_array.py
convert_unit
Convert the value from one unit system to another.
:param unit_str: New unit in string form
Source code in src/easyscience/variable/descriptor_array.py
__copy__
__repr__
Return a string representation of the DescriptorArray, showing its name, value, variance, and unit. Large arrays are summarized for brevity.
Source code in src/easyscience/variable/descriptor_array.py
as_dict
Dict representation of the current DescriptorArray. The dict contains the value, unit and variances, in addition to the properties of DescriptorBase.
Source code in src/easyscience/variable/descriptor_array.py
_apply_operation
Perform element-wise operations with another DescriptorNumber, DescriptorArray, list, or number.
:param other: The object to operate on. Must be a DescriptorArray or DescriptorNumber with compatible units, or a list with the same shape if the DescriptorArray is dimensionless. :param operation: The operation to perform :return: A new DescriptorArray representing the result of the operation.
Source code in src/easyscience/variable/descriptor_array.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
_rapply_operation
Handle reverse operations for DescriptorArrays, DescriptorNumbers, lists, and scalars.
Ensures unit compatibility when other is a DescriptorNumber.
Source code in src/easyscience/variable/descriptor_array.py
__array_ufunc__
DescriptorArray does not generally support Numpy array functions.
For example, np.argwhere(descriptorArray: DescriptorArray) should fail.
Modify this function if you want to add such functionality.
Source code in src/easyscience/variable/descriptor_array.py
__array_function__
DescriptorArray does not generally support Numpy array functions.
For example, np.argwhere(descriptorArray: DescriptorArray) should fail.
Modify this function if you want to add such functionality.
Source code in src/easyscience/variable/descriptor_array.py
__add__
Perform element-wise addition with another DescriptorNumber, DescriptorArray, list, or number.
:param other: The object to add. Must be a DescriptorArray or DescriptorNumber with compatible units, or a list with the same shape if the DescriptorArray is dimensionless, or a number. :return: A new DescriptorArray representing the result of the addition.
Source code in src/easyscience/variable/descriptor_array.py
__radd__
Handle reverse addition for DescriptorArrays, DescriptorNumbers, lists, and scalars.
Ensures unit compatibility when other is a DescriptorNumber.
Source code in src/easyscience/variable/descriptor_array.py
__sub__
Perform element-wise subtraction with another DescriptorArray, list, or number.
:param other: The object to subtract. Must be a DescriptorArray with compatible units, or a list with the same shape if the DescriptorArray is dimensionless. :return: A new DescriptorArray representing the result of the subtraction.
Source code in src/easyscience/variable/descriptor_array.py
__rsub__
Perform element-wise subtraction with another DescriptorNumber, list, or number.
:param other: The object to subtract. Must be a DescriptorArray with compatible units, or a list with the same shape if the DescriptorArray is dimensionless. :return: A new DescriptorArray representing the result of the subtraction.
Source code in src/easyscience/variable/descriptor_array.py
__mul__
Perform element-wise multiplication with another DescriptorNumber, DescriptorArray, list, or number.
:param other: The object to multiply. Must be a DescriptorArray or DescriptorNumber with compatible units, or a list with the same shape if the DescriptorArray is dimensionless. :return: A new DescriptorArray representing the result of the addition.
Source code in src/easyscience/variable/descriptor_array.py
__rmul__
Handle reverse multiplication for DescriptorNumbers, lists, and scalars.
Ensures unit compatibility when other is a DescriptorNumber.
Source code in src/easyscience/variable/descriptor_array.py
__truediv__
Perform element-wise division with another DescriptorNumber, DescriptorArray, list, or number.
:param other: The object to use as a denominator. Must be a DescriptorArray or DescriptorNumber with compatible units, or a list with the same shape if the DescriptorArray is dimensionless. :return: A new DescriptorArray representing the result of the addition.
Source code in src/easyscience/variable/descriptor_array.py
__rtruediv__
Handle reverse division for DescriptorNumbers, lists, and scalars.
Ensures unit compatibility when other is a DescriptorNumber.
Source code in src/easyscience/variable/descriptor_array.py
__pow__
Perform element-wise exponentiation with another DescriptorNumber or number.
:param other: The object to use as a denominator. Must be a number or DescriptorNumber with no unit or variance. :return: A new DescriptorArray representing the result of the addition.
Source code in src/easyscience/variable/descriptor_array.py
__rpow__
Defers reverse pow with a descriptor array, a ** array.
Exponentiation with regards to an array does not make sense,
and is not implemented.
Source code in src/easyscience/variable/descriptor_array.py
__neg__
Negate all values in the DescriptorArray.
Source code in src/easyscience/variable/descriptor_array.py
__abs__
Replace all elements in the DescriptorArray with their absolute values. Note that this is different from the norm of the DescriptorArray.
Source code in src/easyscience/variable/descriptor_array.py
__getitem__
Slice using scipp syntax. Defer slicing to scipp.
Source code in src/easyscience/variable/descriptor_array.py
__delitem__
Defer slicing to scipp. This should fail, since scipp does not support delitem.
__setitem__
setitem via slice is not allowed, since we currently do not give back a view to the DescriptorArray upon calling __getitem.
Source code in src/easyscience/variable/descriptor_array.py
trace
Computes the trace over the descriptor array. The submatrix defined dimension1 and dimension2 must be square.
For a rank k tensor, the trace will run over the firs two dimensions, resulting in a rank k-2 tensor.
:param dimension1, dimension2: First and second dimension to perform trace over. Must be in self.dimensions.
If not defined, the trace will be taken over the first two dimensions.
Source code in src/easyscience/variable/descriptor_array.py
sum
Uses scipp to sum over the requested dims.
:param dim: The dim(s) in the scipp array to sum over. If None, will sum over all dims.
Source code in src/easyscience/variable/descriptor_array.py
_base_unit
Returns the base unit of the current array.
For example, if the unit is 100m, returns m.
Source code in src/easyscience/variable/descriptor_array.py
easyscience.variable.DescriptorStr
Bases: DescriptorBase
A Descriptor for string values.
Source code in src/easyscience/variable/descriptor_str.py
__init__
__init__(
name,
value,
unique_name=None,
description=None,
url=None,
display_name=None,
parent=None,
)
Source code in src/easyscience/variable/descriptor_str.py
__repr__
Return printable representation.
easyscience.variable.DescriptorBool
Bases: DescriptorBase
A Descriptor for boolean values.
Source code in src/easyscience/variable/descriptor_bool.py
__init__
__init__(
name,
value,
unique_name=None,
description=None,
url=None,
display_name=None,
parent=None,
)
Source code in src/easyscience/variable/descriptor_bool.py
__repr__
Return printable representation.
easyscience.variable.DescriptorAnyType
Bases: DescriptorBase
A Descriptor for any type that does not fit the other Descriptors. Should be avoided when possible.
It was created to hold the symmetry operations used in the SpaceGroup class of EasyCrystallography.
Source code in src/easyscience/variable/descriptor_any_type.py
__init__
__init__(
name,
value,
unique_name=None,
description=None,
url=None,
display_name=None,
parent=None,
)
Constructor for the DescriptorAnyType class
param name: Name of the descriptor
param value: Value of the descriptor
param description: Description of the descriptor
param url: URL of the descriptor
param display_name: Display name of the descriptor
param parent: Parent of the descriptor
.. note:: Undo/Redo functionality is implemented for the attributes variance, error, unit and value.
Source code in src/easyscience/variable/descriptor_any_type.py
__copy__
__repr__
Return a string representation of the DescriptorAnyType, showing its name and value.
Source code in src/easyscience/variable/descriptor_any_type.py
Parameters
easyscience.variable.Parameter
Bases: DescriptorNumber
A Parameter is a DescriptorNumber which can be used in fitting. It has additional fields to facilitate this.
Source code in src/easyscience/variable/parameter.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | |
independent
property
writable
Is the parameter independent?
:return: True = independent, False = dependent
dependency_expression
property
writable
Get the dependency expression of this parameter.
:return: The dependency expression of this parameter.
dependency_map
property
writable
Get the dependency map of this parameter.
:return: The dependency map of this parameter.
value_no_call_back
property
Get the currently hold value of self suppressing call back.
:return: Value of self without unit.
full_value
property
writable
Get the value of self as a scipp scalar. This is should be usable for most cases.
If a scipp scalar is not acceptable then the raw value can be obtained through obj.value.
:return: Value of self with unit and variance.
value
property
writable
Get the value of self as a Number.
:return: Value of self without unit.
fixed
property
writable
Can the parameter vary while fitting?
:return: True = fixed, False = can vary
__init__
__init__(
name,
value,
unit='',
variance=0.0,
min=-np.inf,
max=np.inf,
fixed=False,
unique_name=None,
description=None,
url=None,
display_name=None,
callback=property(),
parent=None,
**kwargs,
)
This class is an extension of a DescriptorNumber. Where the descriptor was for static
objects, a Parameter is for dynamic objects. A parameter has the ability to be used in fitting and has
additional fields to facilitate this.
:param name: Name of this object :param value: Value of this object :param unit: This object can have a physical unit associated with it :param variance: The variance of the value :param min: The minimum value for fitting :param max: The maximum value for fitting :param fixed: If the parameter is free to vary during fitting :param description: A brief summary of what this object is :param url: Lookup url for documentation/information :param display_name: The name of the object as it should be displayed :param parent: The object which is the parent to this one
Note:
Undo/Redo functionality is implemented for the attributes value, variance, error, min, max, bounds, fixed, unit
Source code in src/easyscience/variable/parameter.py
from_dependency
classmethod
Create a dependent Parameter directly from a dependency expression.
:param name: The name of the parameter :param dependency_expression: The dependency expression to evaluate. This should be a string which can be evaluated by the ASTEval interpreter. :param dependency_map: A dictionary of dependency expression symbol name and dependency object pairs. This is inserted into the asteval interpreter to resolve dependencies. :param kwargs: Additional keyword arguments to pass to the Parameter constructor. :return: A new dependent Parameter object.
Source code in src/easyscience/variable/parameter.py
_update
Update the parameter. This is called by the DescriptorNumbers/Parameters who have this Parameter as a dependency.
Source code in src/easyscience/variable/parameter.py
make_dependent_on
Make this parameter dependent on another parameter. This will overwrite the current value, unit, variance, min and max.
How to use the dependency map: If a parameter c has a dependency expression of 'a + b', where a and b are parameters belonging to the model class, then the dependency map needs to have the form {'a': model.a, 'b': model.b}, where model is the model class. I.e. the values are the actual objects, whereas the keys are how they are represented in the dependency expression.
The dependency map is not needed if the dependency expression uses the unique names of the parameters. Unique names in dependency expressions are defined by quotes, e.g. 'Parameter_0' or "Parameter_0" depending on the quotes used for the expression.
:param dependency_expression: The dependency expression to evaluate. This should be a string which can be evaluated by a python interpreter.
:param dependency_map: A dictionary of dependency expression symbol name and dependency object pairs. This is inserted into the asteval interpreter to resolve dependencies.
Source code in src/easyscience/variable/parameter.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
make_independent
Make this parameter independent. This will remove the dependency expression, the dependency map and the dependency interpreter.
:return: None
Source code in src/easyscience/variable/parameter.py
variance
Set the variance.
:param variance_float: Variance as a float
Source code in src/easyscience/variable/parameter.py
error
Set the standard deviation for the parameter.
:param value: New error value
Source code in src/easyscience/variable/parameter.py
_convert_unit
Perform unit conversion. The value, max and min can change on unit change.
:param new_unit: new unit :return: None
Source code in src/easyscience/variable/parameter.py
convert_unit
Perform unit conversion. The value, max and min can change on unit change.
:param new_unit: new unit :return: None
Source code in src/easyscience/variable/parameter.py
as_dict
Overwrite the as_dict method to handle dependency information.
Source code in src/easyscience/variable/parameter.py
_revert_dependency
Revert the dependency to the old dependency. This is used when an error is raised during setting the dependency.
Source code in src/easyscience/variable/parameter.py
_process_dependency_unique_names
Add the unique names of the parameters to the ASTEval interpreter. This is used to evaluate the dependency expression.
:param dependency_expression: The dependency expression to be evaluated
Source code in src/easyscience/variable/parameter.py
from_dict
classmethod
Custom deserialization to handle parameter dependencies. Override the parent method to handle dependency information.
Source code in src/easyscience/variable/parameter.py
__copy__
__repr__
Return printable representation of a Parameter object.
Source code in src/easyscience/variable/parameter.py
__add__
Source code in src/easyscience/variable/parameter.py
__radd__
Source code in src/easyscience/variable/parameter.py
__sub__
Source code in src/easyscience/variable/parameter.py
__rsub__
Source code in src/easyscience/variable/parameter.py
__mul__
Source code in src/easyscience/variable/parameter.py
__rmul__
Source code in src/easyscience/variable/parameter.py
__truediv__
Source code in src/easyscience/variable/parameter.py
__rtruediv__
Source code in src/easyscience/variable/parameter.py
__pow__
Source code in src/easyscience/variable/parameter.py
__neg__
Source code in src/easyscience/variable/parameter.py
__abs__
Source code in src/easyscience/variable/parameter.py
resolve_pending_dependencies
Resolve pending dependencies after deserialization.
This method should be called after all parameters have been deserialized to establish dependency relationships using serializer_ids.
Source code in src/easyscience/variable/parameter.py
_find_parameter_by_serializer_id
Find a parameter by its serializer_id from all parameters in the global map.
Source code in src/easyscience/variable/parameter.py
The Parameter class extends DescriptorNumber with fitting capabilities, bounds, and dependency relationships.
Base Classes for Models
BasedBase
easyscience.base_classes.BasedBase
Bases: SerializerComponent
Source code in src/easyscience/base_classes/based_base.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
__slots__
class-attribute
instance-attribute
__init__
Source code in src/easyscience/base_classes/based_base.py
__reduce__
Make the class picklable. Due to the nature of the dynamic class definitions special measures need to be taken.
:return: Tuple consisting of how to make the object :rtype: tuple
Source code in src/easyscience/base_classes/based_base.py
generate_bindings
Generate or re-generate bindings to an interface (if exists)
:raises: AttributeError
Source code in src/easyscience/base_classes/based_base.py
switch_interface
Switch or create a new interface.
Source code in src/easyscience/base_classes/based_base.py
get_parameters
Get all parameter objects as a list.
:return: List of Parameter objects.
Source code in src/easyscience/base_classes/based_base.py
_get_linkable_attributes
Get all objects which can be linked against as a list.
:return: List of Descriptor/Parameter objects.
Source code in src/easyscience/base_classes/based_base.py
get_fit_parameters
Get all objects which can be fitted (and are not fixed) as a list.
:return: List of Parameter objects which can be used in fitting.
Source code in src/easyscience/base_classes/based_base.py
__dir__
This creates auto-completion and helps out in iPython notebooks.
:return: list of function and parameter names for auto-completion
Source code in src/easyscience/base_classes/based_base.py
__copy__
as_dict
Convert an object into a full dictionary using SerializerDict.
This is a shortcut for obj.encode(encoder=SerializerDict)
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
Source code in src/easyscience/base_classes/based_base.py
Base class providing serialization, global object registration, and interface management.
ObjBase
easyscience.base_classes.ObjBase
Bases: BasedBase
This is the base class for which all higher level classes are built off of.
NOTE: This object is serializable only if parameters are supplied as:
ObjBase(a=value, b=value). For Parameter or Descriptor objects we can
cheat with ObjBase(*[Descriptor(...), Parameter(...), ...]).
Source code in src/easyscience/base_classes/obj_base.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
__init__
Set up the base class.
:param name: Name of this object :param args: Any arguments? :param kwargs: Fields which this class should contain
Source code in src/easyscience/base_classes/obj_base.py
_add_component
Dynamically add a component to the class. This is an internal method, though can be called remotely. The recommended alternative is to use typing, i.e.
.. code-block:: python
class Foo(Bar):
def __init__(self, foo: Parameter, bar: Parameter):
super(Foo, self).__init__(bar=bar)
self._add_component("foo", foo)
:param key: Name of component to be added :param component: Component to be added :return: None
Source code in src/easyscience/base_classes/obj_base.py
__setattr__
Source code in src/easyscience/base_classes/obj_base.py
__repr__
__getter
staticmethod
__setter
staticmethod
Source code in src/easyscience/base_classes/obj_base.py
Container class for creating scientific models with parameters. All user-defined models should inherit from this class.
Collections
easyscience.base_classes.CollectionBase
Bases: BasedBase, MutableSequence
This is the base class for which all higher level classes are built off of.
NOTE: This object is serializable only if parameters are supplied as:
ObjBase(a=value, b=value). For Parameter or Descriptor objects we can
cheat with ObjBase(*[Descriptor(...), Parameter(...), ...]).
Source code in src/easyscience/base_classes/collection_base.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
data
property
The data function returns a tuple of the keyword arguments passed to the constructor. This is useful for when you need to pass in a dictionary of data to other functions, such as with matplotlib's plot function.
:param self: Access attributes of the class within the method :return: The values of the attributes in a tuple :doc-author: Trelent
__init__
Set up the base collection class.
:param name: Name of this object :type name: str :param args: selection of :param _kwargs: Fields which this class should contain :type _kwargs: dict
Source code in src/easyscience/base_classes/collection_base.py
insert
Insert an object into the collection at an index.
:param index: Index for EasyScience object to be inserted. :type index: int :param value: Object to be inserted. :type value: Union[BasedBase, DescriptorBase] :return: None :rtype: None
Source code in src/easyscience/base_classes/collection_base.py
__getitem__
Get an item in the collection based on its index.
:param idx: index or slice of the collection.
:type idx: Union[int, slice]
:return: Object at index idx
:rtype: Union[Parameter, Descriptor, ObjBase, 'CollectionBase']
Source code in src/easyscience/base_classes/collection_base.py
__setitem__
Set an item via it's index.
:param key: Index in self. :type key: int :param value: Value which index key should be set to. :type value: Any
Source code in src/easyscience/base_classes/collection_base.py
__delitem__
Try to delete an idem by key.
:param key: :type key: :return: :rtype:
Source code in src/easyscience/base_classes/collection_base.py
__len__
Get the number of items in this collection
:return: Number of items in this collection. :rtype: int
_convert_to_dict
Convert ones self into a serialized form.
:return: dictionary of ones self :rtype: dict
Source code in src/easyscience/base_classes/collection_base.py
__repr__
sort
Sort the collection according to the given mapping.
:param mapping: mapping function to sort the collection. i.e. lambda parameter: parameter.value :type mapping: Callable :param reverse: Reverse the sorting. :type reverse: bool
Source code in src/easyscience/base_classes/collection_base.py
Mutable sequence container for scientific objects with automatic parameter tracking.
Fitting and Optimization
Fitter
easyscience.fitting.Fitter
Fitter is a class which makes it possible to undertake fitting utilizing one of the supported minimizers.
Source code in src/easyscience/fitting/fitter.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
available_minimizers
property
Get a list of the names of available fitting minimizers
:return: List of available fitting minimizers :rtype: List[str]
minimizer
property
Get the current fitting minimizer object.
:return: :rtype: MinimizerBase
tolerance
property
writable
Get the tolerance for the minimizer.
:return: Tolerance for the minimizer
max_evaluations
property
writable
Get the maximal number of evaluations for the minimizer.
:return: Maximal number of steps for the minimizer
fit_function
property
writable
The raw fit function that the optimizer will call (no wrapping) :return: Raw fit function
fit_object
property
writable
The EasyScience object which will be used as a model :return: EasyScience Model
fit
property
Property which wraps the current fit function from the fitting interface. This property return a wrapped fit
function which converts the input data into the correct shape for the optimizer, wraps the fit function to
re-constitute the independent variables and once the fit is completed, reshape the inputs to those expected.
__init__
Source code in src/easyscience/fitting/fitter.py
make_model
evaluate
convert_to_pars_obj
initialize
Set the model and callable in the calculator interface.
:param fit_object: The EasyScience model object :param fit_function: The function to be optimized against.
Source code in src/easyscience/fitting/fitter.py
create
Create the required minimizer. :param minimizer_enum: The enum of the minimization engine to create.
Source code in src/easyscience/fitting/fitter.py
switch_minimizer
Switch minimizer and initialize.
:param minimizer_enum: The enum of the minimizer to create and instantiate.
Source code in src/easyscience/fitting/fitter.py
_update_minimizer
_fit_function_wrapper
Simple fit function which injects the real X (independent) values into the optimizer function. This will also flatten the results if needed. :param real_x: Independent x parameters to be injected :param flatten: Should the result be a flat 1D array? :return: Wrapped optimizer function.
Source code in src/easyscience/fitting/fitter.py
_precompute_reshaping
staticmethod
Check the dimensions of the inputs and reshape if necessary. :param x: ND matrix of dependent points :param y: N-1D matrix of independent points :param kwargs: Additional key-word arguments :return:
Source code in src/easyscience/fitting/fitter.py
_post_compute_reshaping
staticmethod
Reshape the output of the fitter into the correct dimensions. :param fit_result: Output from the fitter :param x: Input x independent :param y: Input y dependent :return: Reshaped Fit Results
Source code in src/easyscience/fitting/fitter.py
Main fitting engine supporting multiple optimization backends.
Available Minimizers
easyscience.fitting.AvailableMinimizers
dataclass
Bases: AvailableMinimizer, Enum
Source code in src/easyscience/fitting/available_minimizers.py
LMFit_differential_evolution
class-attribute
instance-attribute
LMFit_scipy_least_squares
class-attribute
instance-attribute
Enumeration of available optimization backends.
Fit Results
easyscience.fitting.FitResults
At the moment this is just a dummy way of unifying the returned fit parameters.
Source code in src/easyscience/fitting/minimizers/utils.py
__slots__
class-attribute
instance-attribute
__slots__ = [
'success',
'minimizer_engine',
'fit_args',
'p',
'p0',
'x',
'x_matrices',
'y_obs',
'y_calc',
'y_err',
'engine_result',
'total_results',
]
__init__
Source code in src/easyscience/fitting/minimizers/utils.py
Container for fitting results including parameters, statistics, and diagnostics.
Minimizer Base Classes
easyscience.fitting.minimizers.MinimizerBase
This template class is the basis for all minimizer engines in EasyScience.
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
__init__
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
fit
abstractmethod
fit(
x,
y,
weights,
model=None,
parameters=None,
method=None,
tolerance=None,
max_evaluations=None,
**kwargs,
)
Perform a fit using the engine.
:param x: points to be calculated at :type x: np.ndarray :param y: measured points :type y: np.ndarray :param weights: Weights for supplied measured points :type weights: np.ndarray :param model: Optional Model which is being fitted to :param parameters: Optional parameters for the fit :param method: method for the minimizer to use. :type method: str :param kwargs: Additional arguments for the fitting function. :return: Fit results
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
evaluate
Evaluate the fit function for values of x. Parameters used are either the latest or user supplied. If the parameters are user supplied, it must be in a dictionary of {'parameter_name': parameter_value,...}.
:param x: x values for which the fit function will be evaluated :type x: np.ndarray :param minimizer_parameters: Dictionary of parameters which will be used in the fit function. They must be in a dictionary of {'parameter_name': parameter_value,...} :type minimizer_parameters: dict :param kwargs: additional arguments :return: y values calculated at points x for a set of parameters. :rtype: np.ndarray
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
_get_method_kwargs
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
convert_to_pars_obj
abstractmethod
Create an engine compatible container with the Parameters converted from the base object.
:param par_list: If only a single/selection of parameter is required. Specify as a list :type par_list: List[str] :return: engine Parameters compatible object
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
supported_methods
abstractmethod
staticmethod
Return a list of supported methods for the minimizer.
:return: List of supported methods :rtype: List[str]
all_methods
abstractmethod
staticmethod
Return a list of all available methods for the minimizer.
:return: List of all available methods :rtype: List[str]
convert_to_par_object
abstractmethod
staticmethod
Convert an EasyScience.variable.Parameter object to an engine Parameter object.
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
_prepare_parameters
Prepare the parameters for the minimizer.
:param parameters: Dict of parameters for the minimizer with names as keys.
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
_generate_fit_function
Using the user supplied fit_function, wrap it in such a way we can update Parameter on
iterations.
:return: a fit function which is compatible with bumps models
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
_create_signature
staticmethod
Wrap the function signature. This is done as lmfit wants the function to be in the form: f = (x, a=1, b=2)... Where we need to be generic. Note that this won't hold for much outside of this scope.
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
_error_from_jacobian
staticmethod
Source code in src/easyscience/fitting/minimizers/minimizer_base.py
Abstract base class for all minimizer implementations.
easyscience.fitting.minimizers.LMFit
Bases: MinimizerBase
This is a wrapper to the extended Levenberg-Marquardt Fit: https://lmfit.github.io/lmfit-py/
It allows for the lmfit fitting engine to use parameters declared in an EasyScience.base_classes.ObjBase.
Source code in src/easyscience/fitting/minimizers/minimizer_lmfit.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
__init__
Initialize the minimizer with the ObjBase and the fit_function to be used.
:param obj: Base object which contains the parameters to be fitted :type obj: ObjBase :param fit_function: Function which will be fitted to the data :type fit_function: Callable :param method: Method to be used by the minimizer :type method: str
Source code in src/easyscience/fitting/minimizers/minimizer_lmfit.py
all_methods
staticmethod
Source code in src/easyscience/fitting/minimizers/minimizer_lmfit.py
supported_methods
staticmethod
fit
fit(
x,
y,
weights=None,
model=None,
parameters=None,
method=None,
tolerance=None,
max_evaluations=None,
minimizer_kwargs=None,
engine_kwargs=None,
**kwargs,
)
Perform a fit using the lmfit engine.
:param method: :type method: :param x: points to be calculated at :type x: np.ndarray :param y: measured points :type y: np.ndarray :param weights: Weights for supplied measured points :type weights: np.ndarray :param model: Optional Model which is being fitted to :type model: LMModel :param parameters: Optional parameters for the fit :type parameters: LMParameters :param minimizer_kwargs: Arguments to be passed directly to the minimizer :type minimizer_kwargs: dict :param kwargs: Additional arguments for the fitting function. :return: Fit results :rtype: ModelResult
Source code in src/easyscience/fitting/minimizers/minimizer_lmfit.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
_get_fit_kws
Source code in src/easyscience/fitting/minimizers/minimizer_lmfit.py
convert_to_pars_obj
Create an lmfit compatible container with the Parameters converted from the base object.
:param parameters: If only a single/selection of parameter is required. Specify as a list :return: lmfit Parameters compatible object
Source code in src/easyscience/fitting/minimizers/minimizer_lmfit.py
convert_to_par_object
staticmethod
Convert an EasyScience Parameter object to a lmfit Parameter object.
:return: lmfit Parameter compatible object. :rtype: LMParameter
Source code in src/easyscience/fitting/minimizers/minimizer_lmfit.py
_make_model
Generate a lmfit model from the supplied fit_function and parameters in the base object.
:return: Callable lmfit model :rtype: LMModel
Source code in src/easyscience/fitting/minimizers/minimizer_lmfit.py
_set_parameter_fit_result
Update parameters to their final values and assign a std error to them.
:param fit_result: Fit object which contains info on the fit :return: None :rtype: noneType
Source code in src/easyscience/fitting/minimizers/minimizer_lmfit.py
_gen_fit_results
Convert fit results into the unified FitResults format.
See https://github.com/lmfit/lmfit-py/blob/480072b9f7834b31ff2ca66277a5ad31246843a4/lmfit/model.py#L1272
:param fit_result: Fit object which contains info on the fit :return: fit results container :rtype: FitResults
Source code in src/easyscience/fitting/minimizers/minimizer_lmfit.py
LMFit-based minimizer implementation.
easyscience.fitting.minimizers.Bumps
Bases: MinimizerBase
This is a wrapper to Bumps: https://bumps.readthedocs.io/
It allows for the Bumps fitting engine to use parameters declared in an EasyScience.base_classes.ObjBase.
Source code in src/easyscience/fitting/minimizers/minimizer_bumps.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
__init__
Initialize the fitting engine with a ObjBase and an arbitrary fitting function.
:param obj: Object containing elements of the Parameter class
:type obj: ObjBase
:param fit_function: function that when called returns y values. 'x' must be the first
and only positional argument. Additional values can be supplied by
keyword/value pairs
:type fit_function: Callable
Source code in src/easyscience/fitting/minimizers/minimizer_bumps.py
all_methods
staticmethod
supported_methods
staticmethod
fit
fit(
x,
y,
weights,
model=None,
parameters=None,
method=None,
tolerance=None,
max_evaluations=None,
minimizer_kwargs=None,
engine_kwargs=None,
**kwargs,
)
Perform a fit using the lmfit engine.
:param x: points to be calculated at :type x: np.ndarray :param y: measured points :type y: np.ndarray :param weights: Weights for supplied measured points :type weights: np.ndarray :param model: Optional Model which is being fitted to :type model: lmModel :param parameters: Optional parameters for the fit :type parameters: List[BumpsParameter] :param kwargs: Additional arguments for the fitting function. :param method: Method for minimization :type method: str :return: Fit results :rtype: ModelResult
Source code in src/easyscience/fitting/minimizers/minimizer_bumps.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
convert_to_pars_obj
Create a container with the Parameters converted from the base object.
:param par_list: If only a single/selection of parameter is required. Specify as a list :type par_list: List[str] :return: bumps Parameters list :rtype: List[BumpsParameter]
Source code in src/easyscience/fitting/minimizers/minimizer_bumps.py
convert_to_par_object
staticmethod
Convert an EasyScience.variable.Parameter object to a bumps Parameter object
:return: bumps Parameter compatible object. :rtype: BumpsParameter
Source code in src/easyscience/fitting/minimizers/minimizer_bumps.py
_make_model
Generate a bumps model from the supplied fit_function and parameters in the base object.
Note that this makes a callable as it needs to be initialized with x, y, weights
:return: Callable to make a bumps Curve model :rtype: Callable
Source code in src/easyscience/fitting/minimizers/minimizer_bumps.py
_set_parameter_fit_result
Update parameters to their final values and assign a std error to them.
:param fit_result: Fit object which contains info on the fit :return: None :rtype: noneType
Source code in src/easyscience/fitting/minimizers/minimizer_bumps.py
_gen_fit_results
Convert fit results into the unified FitResults format
:param fit_result: Fit object which contains info on the fit :return: fit results container :rtype: FitResults
Source code in src/easyscience/fitting/minimizers/minimizer_bumps.py
Bumps-based minimizer implementation.
easyscience.fitting.minimizers.DFO
Bases: MinimizerBase
This is a wrapper to Derivative Free Optimisation for Least Square: https://numericalalgorithmsgroup.github.io/dfols/
Source code in src/easyscience/fitting/minimizers/minimizer_dfo.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
__init__
Initialize the fitting engine with a ObjBase and an arbitrary fitting function.
:param obj: Object containing elements of the Parameter class
:type obj: ObjBase
:param fit_function: function that when called returns y values. 'x' must be the first
and only positional argument. Additional values can be supplied by
keyword/value pairs
:type fit_function: Callable
Source code in src/easyscience/fitting/minimizers/minimizer_dfo.py
supported_methods
staticmethod
all_methods
staticmethod
fit
fit(
x,
y,
weights,
model=None,
parameters=None,
method=None,
tolerance=None,
max_evaluations=None,
**kwargs,
)
Perform a fit using the DFO-ls engine.
:param x: points to be calculated at :type x: np.ndarray :param y: measured points :type y: np.ndarray :param weights: Weights for supplied measured points :type weights: np.ndarray :param model: Optional Model which is being fitted to :type model: lmModel :param parameters: Optional parameters for the fit :type parameters: List[bumpsParameter] :param kwargs: Additional arguments for the fitting function. :param method: Method for minimization :type method: str :return: Fit results :rtype: ModelResult
Source code in src/easyscience/fitting/minimizers/minimizer_dfo.py
convert_to_pars_obj
convert_to_par_object
staticmethod
_make_model
Generate a model from the supplied fit_function and parameters in the base object.
Note that this makes a callable as it needs to be initialized with x, y, weights
:return: Callable model which returns residuals :rtype: Callable
Source code in src/easyscience/fitting/minimizers/minimizer_dfo.py
_set_parameter_fit_result
Update parameters to their final values and assign a std error to them.
:param fit_result: Fit object which contains info on the fit :param ci: Confidence interval for calculating errors. Default 95% :return: None :rtype: noneType
Source code in src/easyscience/fitting/minimizers/minimizer_dfo.py
_gen_fit_results
Convert fit results into the unified FitResults format
:param fit_result: Fit object which contains info on the fit :return: fit results container :rtype: FitResults
Source code in src/easyscience/fitting/minimizers/minimizer_dfo.py
_dfo_fit
staticmethod
Method to convert EasyScience styling to DFO-LS styling (yes, again)
:param model: Model which accepts f(x[0]) :type model: Callable :param kwargs: Any additional arguments for dfols.solver :type kwargs: dict :return: dfols fit results container
Source code in src/easyscience/fitting/minimizers/minimizer_dfo.py
_prepare_kwargs
staticmethod
Source code in src/easyscience/fitting/minimizers/minimizer_dfo.py
DFO-LS-based minimizer implementation.
Global State Management
Global Object
easyscience.global_object.GlobalObject
GlobalObject is the assimilated knowledge of EasyScience. Every class based on EasyScience gets brought
into the collective.
Source code in src/easyscience/global_object/global_object.py
__init__
Source code in src/easyscience/global_object/global_object.py
instantiate_stack
The undo/redo stack references the collective. Hence it has to be imported after initialization.
:return: None :rtype: noneType
Source code in src/easyscience/global_object/global_object.py
generate_unique_name
Generate a generic unique name for the object using the class name and a global iterator.
Names are in the format name_prefix_0, name_prefix_1, name_prefix_2, etc.
:param name_prefix: The prefix to be used for the name
Source code in src/easyscience/global_object/global_object.py
Singleton managing global state, logging, and object tracking.
Object Map
easyscience.global_object.Map
Source code in src/easyscience/global_object/map.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
__init__
Source code in src/easyscience/global_object/map.py
vertices
edges
_nested_get
get_item_by_key
is_known
find_type
reset_type
change_type
add_vertex
Source code in src/easyscience/global_object/map.py
add_edge
Source code in src/easyscience/global_object/map.py
get_edges
__generate_edges
A static method generating the edges of the map. Edges are represented as sets with one (a loop back to the vertex) or two vertices
Source code in src/easyscience/global_object/map.py
prune_vertex_from_edge
Source code in src/easyscience/global_object/map.py
prune
find_isolated_vertices
returns a list of isolated vertices.
Source code in src/easyscience/global_object/map.py
find_path
find a path from start_vertex to end_vertex in map
Source code in src/easyscience/global_object/map.py
find_all_paths
find all paths from start_vertex to end_vertex in map
Source code in src/easyscience/global_object/map.py
reverse_route
In this case we have an object and want to know the connections to get to another in reverse. We might not know the start_object. In which case we follow the shortest path to a base vertex. :param end_obj: :type end_obj: :param start_obj: :type start_obj: :return: :rtype:
Source code in src/easyscience/global_object/map.py
is_connected
determines if the map is connected
Source code in src/easyscience/global_object/map.py
_clear
Reset the map to an empty state. Only to be used for testing
Graph-based registry for tracking object relationships and dependencies.
Undo/Redo System
easyscience.global_object.undo_redo.UndoStack
Implement a version of QUndoStack without the QT
Source code in src/easyscience/global_object/undo_redo.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
__init__
Source code in src/easyscience/global_object/undo_redo.py
force_state
push
Add a command to the history stack
Source code in src/easyscience/global_object/undo_redo.py
pop
!! WARNING - TO BE USED WITH EXTREME CAUTION !! !! THIS IS PROBABLY NOT THE FN YOU'RE LOOKING FOR, IT CAN BREAK A LOT OF STUFF !! Sometimes you really don't want the last command. Remove it from the stack
:return: None :rtype: None
Source code in src/easyscience/global_object/undo_redo.py
clear
Remove any commands on the stack and reset the state
Source code in src/easyscience/global_object/undo_redo.py
undo
Undo the last change to the stack
Source code in src/easyscience/global_object/undo_redo.py
redo
Redo the last undo command on the stack
Source code in src/easyscience/global_object/undo_redo.py
beginMacro
Start a bulk update i.e. multiple commands under one undo/redo command
Source code in src/easyscience/global_object/undo_redo.py
endMacro
End a bulk update i.e. multiple commands under one undo/redo command
Source code in src/easyscience/global_object/undo_redo.py
canUndo
canRedo
redoText
Stack-based undo/redo system for parameter changes.
Serialization and I/O
Serializer Components
easyscience.io.SerializerComponent
This base class adds the capability of saving and loading (encoding/decoding, serializing/deserializing) easyscience
objects via the encode and decode methods.
The default encoder is SerializerDict, which converts the object to a dictionary.
Shortcuts for dictionary and encoding is also present.
Source code in src/easyscience/io/serializer_component.py
__deepcopy__
encode
Use an encoder to covert an EasyScience object into another format. Default is to a dictionary using SerializerDict.
:param skip: List of field names as strings to skip when forming the encoded object
:param encoder: The encoder to be used for encoding the data. Default is SerializerDict
:param kwargs: Any additional key word arguments to be passed to the encoder
:return: encoded object containing all information to reform an EasyScience object.
Source code in src/easyscience/io/serializer_component.py
decode
classmethod
Re-create an EasyScience object from the output of an encoder. The default decoder is SerializerDict.
:param obj: encoded EasyScience object :param decoder: decoder to be used to reform the EasyScience object :return: Reformed EasyScience object
Source code in src/easyscience/io/serializer_component.py
as_dict
Convert an EasyScience object into a full dictionary using SerializerDict.
This is a shortcut for obj.encode(encoder=SerializerDict)
:param skip: List of field names as strings to skip when forming the dictionary :return: encoded object containing all information to reform an EasyScience object.
Source code in src/easyscience/io/serializer_component.py
from_dict
classmethod
Re-create an EasyScience object from a full encoded dictionary.
:param obj_dict: dictionary containing the serialized contents (from SerializerDict) of an EasyScience object
:return: Reformed EasyScience object
Source code in src/easyscience/io/serializer_component.py
Base class providing serialization capabilities.
easyscience.io.SerializerDict
Bases: SerializerBase
This is a serializer that can encode and decode EasyScience objects to and from a dictionary.
Source code in src/easyscience/io/serializer_dict.py
encode
Convert an EasyScience object to a dictionary.
:param obj: Object to be encoded. :param skip: List of field names as strings to skip when forming the encoded object :param full_encode: Should the data also be encoded (default False) :param kwargs: Any additional key word arguments to be passed to the encoder :return: object encoded to dictionary containing all information to reform an EasyScience object.
Source code in src/easyscience/io/serializer_dict.py
decode
classmethod
Re-create an EasyScience object from the dictionary representation.
:param d: Dict representation of an EasyScience object. :return: EasyScience object.
Source code in src/easyscience/io/serializer_dict.py
Dictionary-based serialization implementation.
easyscience.io.SerializerBase
This is the base class for creating an encoder/decoder which can convert EasyScience objects. encode and decode are
abstract methods to be implemented for each serializer. It is expected that the helper function _convert_to_dict
will be used as a base for encoding (or the SerializerDict as it's more flexible).
Source code in src/easyscience/io/serializer_base.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
encode
abstractmethod
Abstract implementation of an encoder.
:param obj: Object to be encoded. :param skip: List of field names as strings to skip when forming the encoded object :param kwargs: Any additional key word arguments to be passed to the encoder :return: encoded object containing all information to reform an EasyScience object.
Source code in src/easyscience/io/serializer_base.py
decode
abstractmethod
classmethod
Re-create an EasyScience object from the output of an encoder. The default decoder is SerializerDict.
:param obj: encoded EasyScience object :return: Reformed EasyScience object
Source code in src/easyscience/io/serializer_base.py
get_arg_spec
staticmethod
Get the full argument specification of a function (typically __init__)
:param func: Function to be inspected :return: Tuple of argument spec and arguments
Source code in src/easyscience/io/serializer_base.py
_encode_objs
staticmethod
A JSON serializable dict representation of an object.
:param obj: any object to be encoded
:param skip: List of field names as strings to skip when forming the encoded object
:param kwargs: Key-words to pass to SerializerBase
:return: JSON encoded dictionary
Source code in src/easyscience/io/serializer_base.py
_convert_to_dict
A JSON serializable dict representation of an object.
Source code in src/easyscience/io/serializer_base.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
_convert_from_dict
staticmethod
Recursive method to support decoding dicts and lists containing EasyScience objects
:param d: Dictionary containing JSONed EasyScience objects :return: Reformed EasyScience object
Source code in src/easyscience/io/serializer_base.py
deserialize_dict
staticmethod
Deserialize a dictionary using from_dict for ES objects and SerializerBase otherwise. This method processes constructor arguments, skipping metadata keys starting with '@'.
:param in_dict: dictionary to deserialize :return: deserialized dictionary with constructor arguments
Source code in src/easyscience/io/serializer_base.py
_deserialize_value
staticmethod
Deserialize a single value, using specialized handling for ES objects.
:param value: :return: deserialized value
Source code in src/easyscience/io/serializer_base.py
_is_serialized_easyscience_object
staticmethod
Check if a value represents a serialized ES object.
:param value: :return: True if this is a serialized ES object
Source code in src/easyscience/io/serializer_base.py
_import_class
staticmethod
Import a class from a module name and class name.
:param module_name: name of the module :param class_name: name of the class :return: the imported class :raises ImportError: if module cannot be imported :raises ValueError: if class is not found in module
Source code in src/easyscience/io/serializer_base.py
_recursive_encoder
Walk through an object encoding it
Source code in src/easyscience/io/serializer_base.py
Base serialization functionality.
Models and Examples
Polynomial Model
easyscience.models.Polynomial
Bases: ObjBase
A polynomial model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the model. |
'polynomial'
|
coefficients
|
Optional[Union[Iterable[Union[float, Parameter]], CollectionBase]]
|
The coefficients of the polynomial. |
None
|
Source code in src/easyscience/models/polynomial.py
__init__
Source code in src/easyscience/models/polynomial.py
__call__
__repr__
Source code in src/easyscience/models/polynomial.py
Built-in polynomial model for demonstration and testing.
Job Management
Analysis and Experiments
easyscience.job.AnalysisBase
Bases: ObjBase
This virtual class allows for the creation of technique-specific Analysis objects.
Source code in src/easyscience/job/analysis.py
__init__
calculate_theory
abstractmethod
fit
abstractmethod
easyscience.job.ExperimentBase
Bases: ObjBase
This virtual class allows for the creation of technique-specific Experiment objects.
Source code in src/easyscience/job/experiment.py
__init__
easyscience.job.JobBase
Bases: ObjBase
This virtual class allows for the creation of technique-specific Job objects.
Source code in src/easyscience/job/job.py
__init__
theoretical_model
abstractmethod
calculate_theory
abstractmethod
easyscience.job.TheoreticalModelBase
Bases: ObjBase
This virtual class allows for the creation of technique-specific Theory objects.
Source code in src/easyscience/job/theoreticalmodel.py
__init__
__str__
Utility Functions
Decorators
easyscience.global_object.undo_redo.property_stack
Decorate a property setter with undo/redo functionality
This decorator can be used as:
@property_stack def func() ....
or
@property_stack("This is the undo/redo text) def func() ....
In the latter case the argument is a string which might be evaluated. The possible markups for this string are;
obj - The thing being operated on
func - The function being called
name - The name of the function being called.
old_value - The pre-set value
new_value - The post-set value
An example would be Function {name}: Set from {old_value} to {new_value}
Source code in src/easyscience/global_object/undo_redo.py
Decorator for properties that should be tracked in the undo/redo system.
Class Tools
easyscience.utils.classTools.addLoggedProp
Source code in src/easyscience/utils/classTools.py
Utility for adding logged properties to classes.
String Utilities
easyscience.utils.string
transformation_to_string
transformation_to_string(
matrix,
translation_vec=(0, 0, 0),
components=('x', 'y', 'z'),
c='',
delim=',',
)
Convenience method. Given matrix returns string, e.g. x+2y+1/4 :param matrix :param translation_vec :param components: either ('x', 'y', 'z') or ('a', 'b', 'c') :param c: optional additional character to print (used for magmoms) :param delim: delimiter :return: xyz string
Source code in src/easyscience/utils/string.py
Parameter Dependencies
easyscience.variable.parameter_dependency_resolver.resolve_all_parameter_dependencies
Recursively find all Parameter objects in an object hierarchy and resolve their pending dependencies.
This function should be called after deserializing a complex object that contains Parameters with dependencies to ensure all dependency relationships are properly established.
:param obj: The object to search for Parameters (can be a single Parameter, list, dict, or complex object)
Source code in src/easyscience/variable/parameter_dependency_resolver.py
Resolve all pending parameter dependencies after deserialization.
easyscience.variable.parameter_dependency_resolver.get_parameters_with_pending_dependencies
Find all Parameter objects in an object hierarchy that have pending dependencies.
:param obj: The object to search for Parameters :return: List of Parameters with pending dependencies
Source code in src/easyscience/variable/parameter_dependency_resolver.py
Find parameters that have unresolved dependencies.
Constants and Enumerations
The easyscience.global_object is a global singleton instance managing application state.
Exception Classes
easyscience.fitting.minimizers.FitError
Bases: Exception
Source code in src/easyscience/fitting/minimizers/utils.py
Exception raised when fitting operations fail.
Usage Examples
For practical usage examples and tutorials, see:
- Overview - Introduction and key concepts
- Fitting Introduction - Comprehensive fitting guide
- Installation - Installation instructions
The API reference covers all public classes and methods. For implementation details and advanced usage patterns, refer to the source code and test suites in the repository.