Skip to content

[BUG] Problem with rydberg_h function and juliacall #583

Closed
@vrige

Description

@vrige

Hi, I am new to Julia and Bloqade, so I may be wrong, but I think I have found an issue in using the function rydberg_h using juliacall from a python program. I have tested the same code in julia (without using Juliacall) and this problem doesn't arise.
More precisely, the function jl.Bloqade.rydberg_h(atoms, Ω=Ω, Δ=Δ, ϕ =ϕ) doesn't work in my python code, while jl.Bloqade.rydberg_h(atoms, Ω=Ω, Δ=Δ) works perfectly.

from juliacall import Main as jl, convert as jlconvert
from juliacall import Pkg as jlPkg
import numpy as np
import matplotlib.pyplot as plt
from time import time
from math import pi as pi

jlPkg.activate(".")
jlPkg.status()

jl.seval("using Graphs")
#jl.seval("using BloqadeExpr")
jl.seval("using Bloqade")
jl.seval("using Random")
jl.seval("using GenericTensorNetworks")
jl.seval("using Optim")
jl.seval("using PythonCall")
jl.seval("using Plots")

jl.Random.seed_b(3)
atoms = jl.Bloqade.generate_sites(jl.Bloqade.SquareLattice(), 3, 4, scale=4.5)
atoms = jl.Bloqade.random_dropout(atoms, 0.3)

jl.Bloqade.plot(atoms, blockade_radius=7.5)

graph = jl.Bloqade.BloqadeMIS.unit_disk_graph(atoms, 7.5)
mis_size_and_counting = jl.getindex(jl.GenericTensorNetworks.solve(jl.GenericTensorNetworks.IndependentSet(graph), jl.GenericTensorNetworks.CountingMax()))
print(jl.getindex(mis_size_and_counting))

total_time = 3.0
Ω_max = 2 * pi * 4
ϕ_max = 47.0 / (2 * pi * 1e6)
time_points = np.array([0.0, 0.1, 2.1, 2.2, total_time])
amplitude_value = np.array([0.0, Ω_max, Ω_max, 0, 0])
phase_values = np.array([0.0, ϕ_max, ϕ_max, 0, 0])
detuning_values = np.array([0.0, Ω_max, Ω_max, 0, 0])

time_points_jl = jlconvert(jl.Array, time_points)
amplitude_value_jl = jlconvert(jl.Array, amplitude_value)
phase_values_jl = jlconvert(jl.Array, phase_values)
detuning_values_jl = jlconvert(jl.Array, detuning_values)

Omega = jl.Bloqade.piecewise_linear(clocks=time_points_jl, values=amplitude_value_jl)
Delta = jl.Bloqade.piecewise_linear(clocks=time_points_jl, values=phase_values_jl)
Phi = jl.Bloqade.piecewise_linear(clocks=time_points_jl, values=detuning_values_jl)

T_max = time_points[-1]

number_of_shots = 100

start = time()
hamiltonian = jl.Bloqade.rydberg_h(atoms,  Ω=Omega, Δ=Delta, ϕ=Phi)
reg = jl.Bloqade.zero_state(jl.Bloqade.nqubits(hamiltonian))
prob = jl.Bloqade.SchrodingerProblem(reg, T_max, hamiltonian)
jl.Bloqade.emulate_b(prob)
jl.println(jl.Bloqade.measure(reg, nshots=number_of_shots))
end = time()

print("time: ", end - start)

This is the error that I receive:

Traceback (most recent call last):
  File "/home/path/PycharmProjects/aquila_tesi/testing_julia.py", line 56, in <module>
    hamiltonian = jl.Bloqade.rydberg_h(atoms, Ω=Ω, Δ=Δ, ϕ=ϕ)
  File "/home/path/.julia/packages/PythonCall/1f5yE/src/jlwrap/any.jl", line 208, in __call__
    return self._jl_callmethod($(pyjl_methodnum(pyjlany_call)), args, kwargs)
juliacall.JuliaError: MethodError: no method matching rydberg_h(::AtomList{2, Float64}; φ::Waveform{BloqadeWaveforms.PiecewiseLinear{Float64, Interpolations.Extrapolation{Float64, 1, Interpolations.GriddedInterpolation{Float64, 1, Float64, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Tuple{Vector{Float64}}}, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Interpolations.Throw{Nothing}}}, Float64}, Ω::Waveform{BloqadeWaveforms.PiecewiseLinear{Float64, Interpolations.Extrapolation{Float64, 1, Interpolations.GriddedInterpolation{Float64, 1, Float64, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Tuple{Vector{Float64}}}, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Interpolations.Throw{Nothing}}}, Float64}, Δ::Waveform{BloqadeWaveforms.PiecewiseLinear{Float64, Interpolations.Extrapolation{Float64, 1, Interpolations.GriddedInterpolation{Float64, 1, Float64, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Tuple{Vector{Float64}}}, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Interpolations.Throw{Nothing}}}, Float64})

Closest candidates are:
  rydberg_h(::Any; C, Ω, ϕ, Δ) got unsupported keyword argument "φ"
   @ BloqadeExpr ~/.julia/packages/BloqadeExpr/1c235/src/interface.jl:77
  rydberg_h(::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any) got unsupported keyword arguments "φ", "Ω", "Δ"
   @ BloqadeExpr ~/.julia/packages/BloqadeExpr/1c235/src/interface.jl:81

Stacktrace:
 [1] kwerr(::NamedTuple{(:φ, :Ω, :Δ), Tuple{Waveform{BloqadeWaveforms.PiecewiseLinear{Float64, Interpolations.Extrapolation{Float64, 1, Interpolations.GriddedInterpolation{Float64, 1, Float64, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Tuple{Vector{Float64}}}, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Interpolations.Throw{Nothing}}}, Float64}, Waveform{BloqadeWaveforms.PiecewiseLinear{Float64, Interpolations.Extrapolation{Float64, 1, Interpolations.GriddedInterpolation{Float64, 1, Float64, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Tuple{Vector{Float64}}}, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Interpolations.Throw{Nothing}}}, Float64}, Waveform{BloqadeWaveforms.PiecewiseLinear{Float64, Interpolations.Extrapolation{Float64, 1, Interpolations.GriddedInterpolation{Float64, 1, Float64, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Tuple{Vector{Float64}}}, Interpolations.Gridded{Interpolations.Linear{Interpolations.Throw{Interpolations.OnGrid}}}, Interpolations.Throw{Nothing}}}, Float64}}}, ::Function, ::AtomList{2, Float64})
   @ Base ./error.jl:165
 [2] pyjlany_call(self::typeof(rydberg_h), args_::Py, kwargs_::Py)
   @ PythonCall ~/.julia/packages/PythonCall/1f5yE/src/jlwrap/any.jl:34
 [3] _pyjl_callmethod(f::Any, self_::Ptr{PythonCall.C.PyObject}, args_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
   @ PythonCall ~/.julia/packages/PythonCall/1f5yE/src/jlwrap/base.jl:69
 [4] _pyjl_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
   @ PythonCall.C ~/.julia/packages/PythonCall/1f5yE/src/cpython/jlwrap.jl:47

Process finished with exit code 1

I feel like the function mistakes the symbol ϕ for the symbol φ, so it is not able to find the right function to call because the parameters are different.

I am using pycharm with an Anaconda environment.
For the julia dependecies i am suing a .toml file with the following package versions:

Plots = "1.29"
Optim = "1.7.6"
GenericTensorNetworks = "1.3.4"
Graphs = "1.7"
CUDA = "4"
Adapt = "3.6.2"
Bloqade = "0.1.23"
BloqadeExpr = "0.1"
BloqadeKrylov = "0.1"
BloqadeLattices = "0.1"
BloqadeMIS = "0.1"
BloqadeODE = "0.1"
BloqadeWaveforms = "0.1"
ColorSchemes = "3"
Colors = "0.12"
ForwardDiff = "0.10"
Measurements = "2"
PythonCall = "0.8,0.9"
Reexport = "1"
Yao = "0.8"
YaoSubspaceArrayReg = "0.1"
julia = "1.6.3"

While on pkg.status:

Status `~/.julia/environments/v1.9/Project.toml`
  [79e6a3ab] Adapt v3.6.2
  [bd27d05e] Bloqade v0.1.23
  [bd27d05e] BloqadeExpr v0.1.13
  [34da2185] Compat v4.6.1
⌃ [3521c873] GenericTensorNetworks v1.3.0
  [86223c79] Graphs v1.8.0
  [429524aa] Optim v1.7.6
  [91a5bcdd] Plots v1.38.16
  [6099a3de] PythonCall v0.9.13

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions