« blib/lib/Quantum/Superpositions/Lazy/Superposition.pm
↑ Summary
blib/lib/Quantum/Superpositions/Lazy/Role/Operation.pm »
| 1 | package Quantum::Superpositions::Lazy::ComputedState; | ||||||||||
| 2 | 15 | $Quantum::Superpositions::Lazy::ComputedState::VERSION = '1.12'; | |||||||||
| 3 | 15 | ▶ | use v5.24; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 15 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 15 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 15 | ▶ | use Quantum::Superpositions::Lazy::Role::Operation; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 15 | ▶ | use Types::Standard qw(ConsumerOf ArrayRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 15 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 15 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 15 | extends "Quantum::Superpositions::Lazy::State"; | |||||||||
| 13 | |||||||||||
| 14 | 15 | has "source" => ( | |||||||||
| 15 | is => "ro", | ||||||||||
| 16 | isa => ArrayRef, | ||||||||||
| 17 | required => 1, | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 15 | has "operation" => ( | |||||||||
| 21 | is => "ro", | ||||||||||
| 22 | isa => ConsumerOf ["Quantum::Superpositions::Lazy::Role::Operation"], | ||||||||||
| 23 | required => 1, | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | sub clone | ||||||||||
| 27 | 3 | ▶ | { | ||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 28 | 3 | my ($self) = @_; | |||||||||
| 29 | |||||||||||
| 30 | return $self->new( | ||||||||||
| 31 | 3 | $self->%{qw(value weight source operation)} | |||||||||
| 32 | ); | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | # TODO: allow merging with regular states | ||||||||||
| 36 | sub merge | ||||||||||
| 37 | 0 | ▶ | { | ||||||||
|
Subroutine
merge: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 38 | 0 | my ($self, $with) = @_; | |||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | croak "cannot merge a state: values mismatch" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | if $self->value ne $with->value; | ||||||||||
| 42 | 0 | ▶ | croak "cannot merge a state: operation mismatch" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | if $self->operation->sign ne $with->operation->sign; | ||||||||||
| 44 | |||||||||||
| 45 | 0 | return $self->new( | |||||||||
| 46 | weight => $self->weight + $with->weight, | ||||||||||
| 47 | operation => $self->operation, | ||||||||||
| 48 | value => $self->value, | ||||||||||
| 49 | source => [$self->source->@*, $with->source->@*], | ||||||||||
| 50 | ); | ||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 15 | 1; | |||||||||
| 54 | |||||||||||
| 55 | =head1 NAME | ||||||||||
| 56 | |||||||||||
| 57 | Quantum::Superpositions::Lazy::ComputedState - a weighted state implementation | ||||||||||
| 58 | with the source of the computation | ||||||||||
| 59 | |||||||||||
| 60 | =head1 DESCRIPTION | ||||||||||
| 61 | |||||||||||
| 62 | This is a subclass of L<Quantum::Superpositions::Lazy::State> with extra fields | ||||||||||
| 63 | that allow tracking of the computation sources that produced the state. Objects | ||||||||||
| 64 | of this class are produced inside the | ||||||||||
| 65 | L<with_sources|Quantum::Superpositions::Lazy/with_sources> block. | ||||||||||
| 66 | |||||||||||
| 67 | =head1 METHODS | ||||||||||
| 68 | |||||||||||
| 69 | All of the methods available in L<Quantum::Superpositions::Lazy::State>, plus: | ||||||||||
| 70 | |||||||||||
| 71 | =head2 operation | ||||||||||
| 72 | |||||||||||
| 73 | Instance of a class consuming the | ||||||||||
| 74 | L<Quantum::Superpositions::Lazy::Role::Operation> role. This can be helpful to | ||||||||||
| 75 | determine what kind of operation was performed to obtain the state. | ||||||||||
| 76 | |||||||||||
| 77 | =head2 source | ||||||||||
| 78 | |||||||||||
| 79 | An array reference of state values that were used in the operation (in order). | ||||||||||
| 80 | The number of elements in the arrayref will depend of the operation type. | ||||||||||
| 81 | |||||||||||