Hello there,
I am relatively new to Julia but I have developed this piece of code (I haven’t posted the full code yet) that is working as intended. However, I’d really appreciate feedbacks on how to improve it and make it more Julian. The main question is that I pass around a struct
and various functions modify it and/or create new struct members. As far as I’ve understood, you don’t really create classes in Julia but here this concept might be adequate as in the end, I would like to bind it to Python.
module mps_encoder
using BitBasis
using Distributions
using ITensors
using LinearAlgebra
using Plots
using Polynomials
struct MPSEncoder
n_qubits::Int
degree::Int
distr::UnivariateDistribution
end
function construct_site_inds(mps_encoder::MPSEncoder)
siteinds("S=1/2", mps_encoder.n_qubits)
end
function quadratic_coefficients(mps_encoder::MPSEncoder)
# Construct the x uniform grid ∈ [0,1]
x = range(0, 1, length = 2^mps_encoder.n_qubits + 1)
y = pdf(mps_encoder.distr, x)
coefficients = Vector{Polynomial}()
for odd ∈ [x for x ∈ 1:2^mps_encoder.n_qubits if isodd(x)]
quad_fit = Polynomials.fit(x[odd:odd+2], y[odd:odd+2], 2)
push!(coefficients, quad_fit)
end
return coefficients
end
let
n_qubits::Int = 3
poly_degree::Int = 2
distr::UnivariateDistribution = Normal(0.5, 0.1)
mps_encoder::MPSEncoder = MPSEncoder(n_qubits, poly_degree, distr)
sites_mps = construct_site_inds(mps_encoder)
@show sites_mps
coefficients = quadratic_coefficients(mps_encoder)
@show coefficients
nothing
end # let
Any help appreciated ! Thanks a lot.
Roland