MurrellGroup / MolecularEvolution.jl

A Julia framework for developing phylogenetic models
MIT License
9 stars 4 forks source link

Message type declaration #25

Closed nossleinad closed 2 weeks ago

nossleinad commented 2 weeks ago

Background

FelNode has the following message type declaration: message::Vector{Partition}.

Problem

Return type of copy_message

The current implementation of copy_message

copy_message(msg::Vector{<:Partition}) = [copy_partition(x) for x in msg]

doesn't always return ::Vector{Partition}. For example:

julia> node.message = [NucleotidePartition(1)];

julia> copy_message(node.message)
1-element Vector{NucleotidePartition}:
 NucleotidePartition([0.0; 0.0; 0.0; 0.0;;], 4, 1, [0.0])

Inconsistent message type declaration

Notice the difference between ::Vector{<:Partition} and ::Vector{Partition}.

This is the function head for internal_message_init:

internal_message_init!(tree::FelNode, empty_message::Vector{<:Partition})

This is the function head for an internal version of branchlength_optim!:

function branchlength_optim!(
    temp_message::Vector{Partition},
    message_to_set::Vector{Partition},
    node::FelNode,
    models,
    partition_list,
    tol;
    bl_optimizer::UnivariateOpt = GoldenSectionOpt()
)

temp_message and message_to_set are initialized through copy_message which can cause a MethodError, since

julia> Vector{NucleotidePartition} <: Vector{Partition}
false

Resolution

Either