From 9dfa46429960a9e64ae16325081dbf978be90dbb Mon Sep 17 00:00:00 2001 From: "Chakrabarti, Sambuddha (Sam)" Date: Wed, 31 Jul 2024 14:10:04 -0400 Subject: [PATCH 1/2] Replaced @kwdef with Base.@kwdef since otherwise package errors --- src/function_data.jl | 8 ++++---- src/internal.jl | 4 ++-- src/time_series_parameters.jl | 2 +- src/time_series_structs.jl | 6 +++--- src/utils/logging.jl | 2 +- test/test_utils.jl | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/function_data.jl b/src/function_data.jl index 874be0098..8b2f01ed4 100644 --- a/src/function_data.jl +++ b/src/function_data.jl @@ -8,7 +8,7 @@ the representation of cost functions `f(x) = proportional_term*x + constant_term - `proportional_term::Float64`: the proportional term in the represented function - `constant_term::Float64`: the constant term in the represented function """ -@kwdef struct LinearFunctionData <: FunctionData +Base.@kwdef struct LinearFunctionData <: FunctionData proportional_term::Float64 constant_term::Float64 end @@ -56,7 +56,7 @@ representation of cost functions - `proportional_term::Float64`: the proportional term in the represented function - `constant_term::Float64`: the constant term in the represented function """ -@kwdef struct QuadraticFunctionData <: FunctionData +Base.@kwdef struct QuadraticFunctionData <: FunctionData quadratic_term::Float64 proportional_term::Float64 constant_term::Float64 @@ -116,7 +116,7 @@ store quantities (x, y), such as (MW, \$/h). # Arguments - `points::Vector{@NamedTuple{x::Float64, y::Float64}}`: the points that define the function """ -@kwdef struct PiecewiseLinearData <: FunctionData +Base.@kwdef struct PiecewiseLinearData <: FunctionData points::Vector{XY_COORDS} function PiecewiseLinearData(points::Vector{<:NamedTuple{(:x, :y)}}) @@ -232,7 +232,7 @@ quantities (x, dy/dx), such as (MW, \$/MWh). `x_coords[1]` and `x_coords[2]`, etc. Must have one fewer elements than `x_coords`. - `c::Union{Nothing, Float64}`: optional, the value to use for the integral from 0 to `x_coords[1]` of this function """ -@kwdef struct PiecewiseStepData <: FunctionData +Base.@kwdef struct PiecewiseStepData <: FunctionData x_coords::Vector{Float64} y_coords::Vector{Float64} diff --git a/src/internal.jl b/src/internal.jl index eff41aaab..bb02bf13f 100644 --- a/src/internal.jl +++ b/src/internal.jl @@ -5,7 +5,7 @@ abstract type UnitsData end @scoped_enum(UnitSystem, SYSTEM_BASE = 0, DEVICE_BASE = 1, NATURAL_UNITS = 2,) -@kwdef mutable struct SystemUnitsSettings <: UnitsData +Base.@kwdef mutable struct SystemUnitsSettings <: UnitsData base_value::Float64 unit_system::UnitSystem end @@ -13,7 +13,7 @@ end serialize(val::SystemUnitsSettings) = serialize_struct(val) deserialize(T::Type{<:SystemUnitsSettings}, val::Dict) = deserialize_struct(T, val) -@kwdef struct SharedSystemReferences <: InfrastructureSystemsType +Base.@kwdef struct SharedSystemReferences <: InfrastructureSystemsType supplemental_attribute_manager::Any = nothing time_series_manager::Any = nothing end diff --git a/src/time_series_parameters.jl b/src/time_series_parameters.jl index 4401b9451..43781384c 100644 --- a/src/time_series_parameters.jl +++ b/src/time_series_parameters.jl @@ -2,7 +2,7 @@ abstract type AbstractTimeSeriesParameters <: InfrastructureSystemsType end struct StaticTimeSeriesParameters <: AbstractTimeSeriesParameters end -@kwdef struct ForecastParameters <: AbstractTimeSeriesParameters +Base.@kwdef struct ForecastParameters <: AbstractTimeSeriesParameters horizon::Dates.Period initial_timestamp::Dates.DateTime interval::Dates.Period diff --git a/src/time_series_structs.jl b/src/time_series_structs.jl index ae023407d..3866e7f77 100644 --- a/src/time_series_structs.jl +++ b/src/time_series_structs.jl @@ -24,7 +24,7 @@ function deserialize_struct(T::Type{<:TimeSeriesKey}, data::Dict) return T(; vals...) end -@kwdef struct StaticTimeSeriesKey <: TimeSeriesKey +Base.@kwdef struct StaticTimeSeriesKey <: TimeSeriesKey time_series_type::Type{<:StaticTimeSeries} name::String initial_timestamp::Dates.DateTime @@ -44,7 +44,7 @@ function make_time_series_key(metadata::StaticTimeSeriesMetadata) ) end -@kwdef struct ForecastKey <: TimeSeriesKey +Base.@kwdef struct ForecastKey <: TimeSeriesKey time_series_type::Type{<:Forecast} name::String initial_timestamp::Dates.DateTime @@ -72,7 +72,7 @@ end Provides counts of time series including attachments to components and supplemental attributes. """ -@kwdef struct TimeSeriesCounts +Base.@kwdef struct TimeSeriesCounts components_with_time_series::Int supplemental_attributes_with_time_series::Int static_time_series_count::Int diff --git a/src/utils/logging.jl b/src/utils/logging.jl index 2dd0fce72..6e861c65e 100644 --- a/src/utils/logging.jl +++ b/src/utils/logging.jl @@ -109,7 +109,7 @@ function _is_level_valid(tracker::LogEventTracker, level::Logging.LogLevel) return level in keys(tracker.events) end -@kwdef struct LoggingConfiguration +Base.@kwdef struct LoggingConfiguration console::Bool = true console_stream::IO = stderr console_level::Base.LogLevel = Logging.Error diff --git a/test/test_utils.jl b/test/test_utils.jl index 82785510d..26d285ed5 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -25,7 +25,7 @@ IS.@scoped_enum Fruit APPLE = 1 ORANGE = 2 @test Fruit.ORANGE isa Fruit @test sort([Fruit.ORANGE, Fruit.APPLE]) == [Fruit.APPLE, Fruit.ORANGE] - @kwdef struct Foo + Base.@kwdef struct Foo fruit::Fruit end @test Foo(1) == Foo(Fruit.APPLE) From 6a2ab6b6e951df988ee0eda2577a02c2a4aa1268 Mon Sep 17 00:00:00 2001 From: "Chakrabarti, Sambuddha (Sam)" Date: Wed, 31 Jul 2024 18:46:52 -0400 Subject: [PATCH 2/2] Instead of Base.@kwdef, now have @kwdef along with import Base: @kwdef in src/Infrastructure.jl --- src/InfrastructureSystems.jl | 1 + src/function_data.jl | 8 ++++---- src/internal.jl | 4 ++-- src/time_series_parameters.jl | 2 +- src/time_series_structs.jl | 6 +++--- src/utils/logging.jl | 2 +- test/test_utils.jl | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/InfrastructureSystems.jl b/src/InfrastructureSystems.jl index 2ce6a0884..6a54f1ee4 100644 --- a/src/InfrastructureSystems.jl +++ b/src/InfrastructureSystems.jl @@ -2,6 +2,7 @@ isdefined(Base, :__precompile__) && __precompile__() module InfrastructureSystems +import Base: @kwdef import CSV import DataFrames import DataFrames: DataFrame diff --git a/src/function_data.jl b/src/function_data.jl index 8b2f01ed4..874be0098 100644 --- a/src/function_data.jl +++ b/src/function_data.jl @@ -8,7 +8,7 @@ the representation of cost functions `f(x) = proportional_term*x + constant_term - `proportional_term::Float64`: the proportional term in the represented function - `constant_term::Float64`: the constant term in the represented function """ -Base.@kwdef struct LinearFunctionData <: FunctionData +@kwdef struct LinearFunctionData <: FunctionData proportional_term::Float64 constant_term::Float64 end @@ -56,7 +56,7 @@ representation of cost functions - `proportional_term::Float64`: the proportional term in the represented function - `constant_term::Float64`: the constant term in the represented function """ -Base.@kwdef struct QuadraticFunctionData <: FunctionData +@kwdef struct QuadraticFunctionData <: FunctionData quadratic_term::Float64 proportional_term::Float64 constant_term::Float64 @@ -116,7 +116,7 @@ store quantities (x, y), such as (MW, \$/h). # Arguments - `points::Vector{@NamedTuple{x::Float64, y::Float64}}`: the points that define the function """ -Base.@kwdef struct PiecewiseLinearData <: FunctionData +@kwdef struct PiecewiseLinearData <: FunctionData points::Vector{XY_COORDS} function PiecewiseLinearData(points::Vector{<:NamedTuple{(:x, :y)}}) @@ -232,7 +232,7 @@ quantities (x, dy/dx), such as (MW, \$/MWh). `x_coords[1]` and `x_coords[2]`, etc. Must have one fewer elements than `x_coords`. - `c::Union{Nothing, Float64}`: optional, the value to use for the integral from 0 to `x_coords[1]` of this function """ -Base.@kwdef struct PiecewiseStepData <: FunctionData +@kwdef struct PiecewiseStepData <: FunctionData x_coords::Vector{Float64} y_coords::Vector{Float64} diff --git a/src/internal.jl b/src/internal.jl index bb02bf13f..eff41aaab 100644 --- a/src/internal.jl +++ b/src/internal.jl @@ -5,7 +5,7 @@ abstract type UnitsData end @scoped_enum(UnitSystem, SYSTEM_BASE = 0, DEVICE_BASE = 1, NATURAL_UNITS = 2,) -Base.@kwdef mutable struct SystemUnitsSettings <: UnitsData +@kwdef mutable struct SystemUnitsSettings <: UnitsData base_value::Float64 unit_system::UnitSystem end @@ -13,7 +13,7 @@ end serialize(val::SystemUnitsSettings) = serialize_struct(val) deserialize(T::Type{<:SystemUnitsSettings}, val::Dict) = deserialize_struct(T, val) -Base.@kwdef struct SharedSystemReferences <: InfrastructureSystemsType +@kwdef struct SharedSystemReferences <: InfrastructureSystemsType supplemental_attribute_manager::Any = nothing time_series_manager::Any = nothing end diff --git a/src/time_series_parameters.jl b/src/time_series_parameters.jl index 43781384c..4401b9451 100644 --- a/src/time_series_parameters.jl +++ b/src/time_series_parameters.jl @@ -2,7 +2,7 @@ abstract type AbstractTimeSeriesParameters <: InfrastructureSystemsType end struct StaticTimeSeriesParameters <: AbstractTimeSeriesParameters end -Base.@kwdef struct ForecastParameters <: AbstractTimeSeriesParameters +@kwdef struct ForecastParameters <: AbstractTimeSeriesParameters horizon::Dates.Period initial_timestamp::Dates.DateTime interval::Dates.Period diff --git a/src/time_series_structs.jl b/src/time_series_structs.jl index 3866e7f77..ae023407d 100644 --- a/src/time_series_structs.jl +++ b/src/time_series_structs.jl @@ -24,7 +24,7 @@ function deserialize_struct(T::Type{<:TimeSeriesKey}, data::Dict) return T(; vals...) end -Base.@kwdef struct StaticTimeSeriesKey <: TimeSeriesKey +@kwdef struct StaticTimeSeriesKey <: TimeSeriesKey time_series_type::Type{<:StaticTimeSeries} name::String initial_timestamp::Dates.DateTime @@ -44,7 +44,7 @@ function make_time_series_key(metadata::StaticTimeSeriesMetadata) ) end -Base.@kwdef struct ForecastKey <: TimeSeriesKey +@kwdef struct ForecastKey <: TimeSeriesKey time_series_type::Type{<:Forecast} name::String initial_timestamp::Dates.DateTime @@ -72,7 +72,7 @@ end Provides counts of time series including attachments to components and supplemental attributes. """ -Base.@kwdef struct TimeSeriesCounts +@kwdef struct TimeSeriesCounts components_with_time_series::Int supplemental_attributes_with_time_series::Int static_time_series_count::Int diff --git a/src/utils/logging.jl b/src/utils/logging.jl index 6e861c65e..2dd0fce72 100644 --- a/src/utils/logging.jl +++ b/src/utils/logging.jl @@ -109,7 +109,7 @@ function _is_level_valid(tracker::LogEventTracker, level::Logging.LogLevel) return level in keys(tracker.events) end -Base.@kwdef struct LoggingConfiguration +@kwdef struct LoggingConfiguration console::Bool = true console_stream::IO = stderr console_level::Base.LogLevel = Logging.Error diff --git a/test/test_utils.jl b/test/test_utils.jl index 26d285ed5..82785510d 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -25,7 +25,7 @@ IS.@scoped_enum Fruit APPLE = 1 ORANGE = 2 @test Fruit.ORANGE isa Fruit @test sort([Fruit.ORANGE, Fruit.APPLE]) == [Fruit.APPLE, Fruit.ORANGE] - Base.@kwdef struct Foo + @kwdef struct Foo fruit::Fruit end @test Foo(1) == Foo(Fruit.APPLE)