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