Skip to content

Commit

Permalink
drop Tectonic and EndpointRanges, add tectonic_jll
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Krastanov <stefan@krastanov.org>
  • Loading branch information
Krastanov committed Dec 27, 2022
1 parent e720875 commit b5cf66d
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 10 deletions.
9 changes: 5 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
name = "Quantikz"
uuid = "b0d11df0-eea3-4d79-b4a5-421488cbf74b"
authors = ["Stefan Krastanov <stefan@krastanov.org>"]
version = "1.1.2"
version = "1.1.3"

[deps]
EndpointRanges = "340492b5-2a47-5f55-813d-aca7ddf97656"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Ghostscript_jll = "61579ee1-b43e-5ca0-a5da-69d92c66a64b"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Tectonic = "9ac5f52a-99c6-489f-af81-462ef484790f"
tectonic_jll = "d7dd28d6-a5e6-559c-9131-7eb760cdacc5"


[compat]
EndpointRanges = "0.2"
FileIO = "1.6"
Ghostscript_jll = "9.53"
ImageMagick = "1.1"
Tectonic = "0.8"
julia = "1.3"
julia = "1.6"
tectonic_jll = "0.11"
98 changes: 98 additions & 0 deletions src/EndpointRanges.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# copied from https://github.com/JuliaArrays/EndpointRanges.jl
# due to the fact that Quantikz was the only dependent of EndpointRanges
# causing some worry about the support that would be available upstream
module VendoredEndpointRanges

import Base: +, -, *, /, ÷, %
using Base: ViewIndex, tail, axes1

export ibegin, iend

abstract type Endpoint end
struct IBegin <: Endpoint end
struct IEnd <: Endpoint end
const ibegin = IBegin()
const iend = IEnd()

(::IBegin)(b::Integer, e::Integer) = b
(::IEnd )(b::Integer, e::Integer) = e
(::IBegin)(r::AbstractRange) = first(r)
(::IEnd )(r::AbstractRange) = last(r)

struct IndexFunction{F<:Function} <: Endpoint
index::F
end
(f::IndexFunction)(r::AbstractRange) = f.index(r)

for op in (:+, :-)
@eval $op(x::Endpoint) = IndexFunction(r->x(r))
end
for op in (:+, :-, :*, :/, :÷, :%)
@eval $op(x::Endpoint, y::Endpoint) = IndexFunction(r->$op(x(r), y(r)))
@eval $op(x::Endpoint, y::Number) = IndexFunction(r->$op(x(r), y))
@eval $op(x::Number, y::Endpoint) = IndexFunction(r->$op(x, y(r)))
end

# deliberately not <: AbstractUnitRange{Int}
abstract type EndpointRange{T} end
struct EndpointUnitRange{F<:Union{Int,Endpoint},L<:Union{Int,Endpoint}} <: EndpointRange{Int}
start::F
stop::L
end
struct EndpointStepRange{F<:Union{Int,Endpoint},L<:Union{Int,Endpoint}} <: EndpointRange{Int}
start::F
step::Int
stop::L
end

(r::EndpointUnitRange)(s::AbstractRange) = r.start(s):r.stop(s)
(r::EndpointUnitRange{Int,E})(s::AbstractRange) where {E<:Endpoint} = r.start:r.stop(s)
(r::EndpointUnitRange{E,Int})(s::AbstractRange) where {E<:Endpoint} = r.start(s):r.stop

(r::EndpointStepRange)(s::AbstractRange) = r.start(s):r.step:r.stop(s)
(r::EndpointStepRange{Int,E})(s::AbstractRange) where {E<:Endpoint} = r.start:r.step:r.stop(s)
(r::EndpointStepRange{E,Int})(s::AbstractRange) where {E<:Endpoint} = r.start(s):r.step:r.stop

(::Colon)(start::Endpoint, stop::Endpoint) = EndpointUnitRange(start, stop)
(::Colon)(start::Endpoint, stop::Int) = EndpointUnitRange(start, stop)
(::Colon)(start::Int, stop::Endpoint) = EndpointUnitRange(start, stop)

(::Colon)(start::Endpoint, step::Int, stop::Endpoint) = EndpointStepRange(start, step, stop)
(::Colon)(start::Endpoint, step::Int, stop::Int) = EndpointStepRange(start, step, stop)
(::Colon)(start::Int, step::Int, stop::Endpoint) = EndpointStepRange(start, step, stop)

function Base.getindex(r::UnitRange, s::EndpointRange)
getindex(r, newindex(axes1(r), s))
end

function Base.getindex(r::AbstractUnitRange, s::EndpointRange)
getindex(r, newindex(axes1(r), s))
end

function Base.getindex(r::StepRange, s::EndpointRange)
getindex(r, newindex(axes1(r), s))
end

function Base.getindex(r::StepRangeLen, s::EndpointRange)
getindex(r, newindex(axes1(r), s))
end

function Base.getindex(r::LinRange, s::EndpointRange)
getindex(r, newindex(axes1(r), s))
end


@inline function Base.to_indices(A, inds, I::Tuple{Union{Endpoint, EndpointRange}, Vararg{Any}})
(newindex(inds[1], I[1]), to_indices(A, (inds)[2:end], Base.tail(I))...)
end

@inline newindices(indsA, inds) = (newindex(indsA[1], inds[1]), newindices(tail(indsA), tail(inds))...)
newindices(::Tuple{}, ::Tuple{}) = ()

newindex(indA, i::Union{Real, AbstractArray, Colon}) = i
newindex(indA, i::EndpointRange) = i(indA)
newindex(indA, i::IBegin) = first(indA)
newindex(indA, i::IEnd) = last(indA)
newindex(indA, i::Endpoint) = i(indA)

end # module
11 changes: 7 additions & 4 deletions src/Quantikz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ module Quantikz
using Base.Filesystem
using Pkg.Artifacts

using EndpointRanges
using FileIO
using Ghostscript_jll
using Tectonic
using tectonic_jll

include("EndpointRanges.jl")
using .VendoredEndpointRanges
const EndpointRanges = VendoredEndpointRanges

export MultiControl, CNOT, CPHASE, SWAP, H, P, Id, U,
MultiControlU,
Expand Down Expand Up @@ -157,7 +160,7 @@ function draw_rectangle!(table,step,targets,str;checkdelete_evenfortarget=false)
m, M = explicit_extrema(table, targets)
targets = explicit_targets(table, targets)
for i in m:M
if i targets
if i targets
if strip(table[i,step-1])==""
push!(deleted, i)
else
Expand Down Expand Up @@ -256,7 +259,7 @@ end

affectedqubits(r::Initialize) = r.targets
function update_table!(qtable,step,r::Initialize)
qvtable = qubitsview(qtable)
qvtable = qubitsview(qtable)
m, M = extrema(r.targets)
targets = r.targets
if collect(targets) == collect(m:M)
Expand Down
6 changes: 4 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Quantikz, Test, EndpointRanges
using Quantikz, Test
using Quantikz.VendoredEndpointRanges
const EndpointRanges = VendoredEndpointRanges

function stringtests()
@testset "Misc string conversions" begin
Expand Down Expand Up @@ -163,4 +165,4 @@ end
end

stringtests()
filetests()
filetests()

0 comments on commit b5cf66d

Please sign in to comment.