Skip to content

Commit 7078b4c

Browse files
committed
1 parent 30a82bc commit 7078b4c

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

src/YaoCompiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module YaoCompiler
22

3-
export @operation,
3+
export @device,
44
@gate,
55
@ctrl,
66
@measure,

src/compiler/intrinsics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export main, apply, measure, barrier, expect
1616
@intrinsic_stub device expect(r::AbstractRegister, ::Locations, nshots::Int)
1717

1818
# this is just for doing overlay since we don't
19-
# have explicit register semantic inside @operation
19+
# have explicit register semantic inside @device
2020
@intrinsic_stub device apply(gate::Routine)
2121
@intrinsic_stub device apply(gate::Routine, ::Locations)
2222
@intrinsic_stub device apply(gate::Routine, ::Locations, ::CtrlLocations)

src/compiler/syntax.jl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ xctrl_locations(ex) = Expr(:call, :($YaoLocations.CtrlLocations), ex)
44
"""
55
@gate <locs> => <gate>
66
7-
Syntax sugar for `apply(gate, locs)`, must be used inside `@operation`.
8-
See also [`@operation`](@ref).
7+
Syntax sugar for `apply(gate, locs)`, must be used inside `@device`.
8+
See also [`@device`](@ref).
99
1010
!!! tips
11-
You don't have to write `@gate` in most cases inside `@operation`.
11+
You don't have to write `@gate` in most cases inside `@device`.
1212
But in case there is ambuigity, you can annotate the expression
1313
with `@gate` explicitly.
1414
"""
@@ -22,8 +22,8 @@ end
2222
"""
2323
@ctrl <ctrl_locs> <locs> => <gate>
2424
25-
Syntax sugar for `apply(gate, locs, ctrl_locs)`, must be used inside `@operation`.
26-
See also [`@operation`](@ref).
25+
Syntax sugar for `apply(gate, locs, ctrl_locs)`, must be used inside `@device`.
26+
See also [`@device`](@ref).
2727
"""
2828
macro ctrl(ctrl_locs, ex::Expr)
2929
@match ex begin
@@ -53,12 +53,12 @@ macro barrier(locs)
5353
end
5454

5555
"""
56-
@operation <function def>
56+
@device <function def>
5757
58-
Annotate a Julia function as YaoLang operation kernel.
58+
Annotate a Julia function as YaoLang device kernel.
5959
"""
60-
macro operation(ex)
61-
esc(operation_m(__module__, ex))
60+
macro device(ex)
61+
esc(device_m(__module__, ex))
6262
end
6363

6464
"""
@@ -71,7 +71,7 @@ on them directly.
7171
"""
7272
function routine_stub end
7373

74-
function operation_m(mod::Module, ex)
74+
function device_m(mod::Module, ex)
7575
is_function(ex) || error("expect a function definition")
7676
jlfn = JLFunction(ex)
7777
isnothing(jlfn.kwargs) || error("kwargs is not supported")
@@ -86,7 +86,7 @@ function codegen_routine(jlfn::JLFunction)
8686

8787
return quote
8888
$(codegen_routine_type(jlfn, typename))
89-
$(codegen_operation(jlfn, typename))
89+
$(codegen_device(jlfn, typename))
9090
$(codegen_inference_limit_heuristics(jlfn, typename))
9191
$(codegen_routine_stub(jlfn, typename))
9292
$(codegen_binding(jlfn, typename))
@@ -112,7 +112,7 @@ function codegen_binding(def::JLFunction, typename)
112112
end
113113
end
114114

115-
function codegen_operation(def::JLFunction, typename)
115+
function codegen_device(def::JLFunction, typename)
116116
self = gensym(:self)
117117
args = name_only.(def.args)
118118

@@ -207,17 +207,17 @@ function transpile_gate_syntax(ex)
207207
:($locs => $gate) => xcall(GlobalRef(Intrinsics, :apply), gate, xlocations(locs))
208208
# this will appear in anonymous function definition
209209
# TODO: disambuigity this and function contains only single line
210-
# @operation function circuit(theta, phi)
210+
# @device function circuit(theta, phi)
211211
# 1 => X
212212
# end
213213
# Expr(:block, stmt1, line::LineNumberNode, stmt2) => ex
214-
Expr(:macrocall, Symbol("@operation"), _...) => error("syntax: cannot have nested @operation")
214+
Expr(:macrocall, Symbol("@device"), _...) => error("syntax: cannot have nested @device")
215215
Expr(:macrocall, name, args...) => begin
216216
if is_syntax_macro(name)
217217
return ex
218218
else
219219
# we force top scope locs=>gate to be treated as gate stmt inside
220-
# all @operation region including non-YaoCompiler macros to make things
220+
# all @device region including non-YaoCompiler macros to make things
221221
# like @inbounds etc. work
222222
return Expr(:macrocall, name, map(transpile_gate_syntax, args)...)
223223
end
@@ -239,8 +239,8 @@ end
239239
ci, nargs = obtain_codeinfo(op)
240240
new = NewCodeInfo(ci)
241241
register = insert!(new.slots, 2, Symbol("#register#"))
242-
operation = insert!(new.slots, 3, Symbol("#op#"))
243-
unpack_operation!(new, operation, nargs)
242+
device = insert!(new.slots, 3, Symbol("#op#"))
243+
unpack_device!(new, device, nargs)
244244
for (v, stmt) in new
245245
@switch stmt begin
246246
@case Expr(:call, GlobalRef(&Intrinsics, name), args...)
@@ -278,9 +278,9 @@ end
278278
ci, nargs = obtain_codeinfo(op)
279279
new = NewCodeInfo(ci)
280280
register = insert!(new.slots, 2, Symbol("#register#"))
281-
operation = insert!(new.slots, 3, Symbol("#op#"))
281+
device = insert!(new.slots, 3, Symbol("#op#"))
282282
glob_locs = insert!(new.slots, 4, Symbol("#locs#"))
283-
unpack_operation!(new, operation, nargs)
283+
unpack_device!(new, device, nargs)
284284

285285
for (v, stmt) in new
286286
_update_slot_stmt(new, v, stmt) do stmt
@@ -327,10 +327,10 @@ end
327327
ci, nargs = obtain_codeinfo(op)
328328
new = NewCodeInfo(ci)
329329
register = insert!(new.slots, 2, Symbol("#register#"))
330-
operation = insert!(new.slots, 3, Symbol("#op#"))
330+
device = insert!(new.slots, 3, Symbol("#op#"))
331331
glob_locs = insert!(new.slots, 4, Symbol("#locs#"))
332332
glob_ctrl = insert!(new.slots, 5, Symbol("#ctrl#"))
333-
unpack_operation!(new, operation, nargs)
333+
unpack_device!(new, device, nargs)
334334

335335
for (v, stmt) in new
336336
_update_slot_stmt(new, v, stmt) do stmt
@@ -398,7 +398,7 @@ function obtain_codeinfo(::Type{Operation{P,Args}}) where {P,Args}
398398
return ci, nargs
399399
end
400400

401-
function unpack_operation!(new::NewCodeInfo, op::NewSlotNumber, nargs::Int)
401+
function unpack_device!(new::NewCodeInfo, op::NewSlotNumber, nargs::Int)
402402
# %parent = op.parent
403403
parent = push!(new, Expr(:call, GlobalRef(Base, :getfield), op, QuoteNode(:parent)))
404404

src/compiler/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ end
7878
end
7979

8080
@noinline function measure_cmp(lhs, rhs)
81-
throw(IntrinsicError("cannot compare measurement result outside @operation"))
81+
throw(IntrinsicError("cannot compare measurement result outside @device"))
8282
end
8383

8484
# struct Chain

test/emulate.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ end
5858
return MeasureResult{typeof(result)}(result)
5959
end
6060

61-
@operation function test_intrinsic(theta, phi)
61+
@device function test_intrinsic(theta, phi)
6262
# syntax sugar
6363
1 => X
6464
@gate 2 => Z
@@ -67,7 +67,7 @@ end
6767
return
6868
end
6969

70-
@operation function test_location_map(theta)
70+
@device function test_location_map(theta)
7171
3:6 => test_intrinsic(theta, 2.5)
7272
@ctrl 1 3:6 => test_intrinsic(theta, 2.1)
7373
return

test/interp.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using YaoCompiler.Intrinsics
88
using CompilerPluginTools
99
using YaoCompiler.Intrinsics: measure
1010

11-
@operation function test_basic(theta, phi)
11+
@device function test_basic(theta, phi)
1212
# syntax sugar
1313
1 => X
1414
@gate 2 => Z
@@ -22,15 +22,15 @@ using YaoCompiler.Intrinsics: measure
2222
return (a = a, b = c)
2323
end
2424

25-
@operation function test_pure_quantum()
25+
@device function test_pure_quantum()
2626
ret = @gate 1:4 => test_basic(1.0, 2.0)
2727
@ctrl 2 1 => Rx(2.2)
2828
return ret
2929
end
3030

3131
ci, type = @yao_code_typed(test_pure_quantum())[1]
3232

33-
@operation function routine2(theta)
33+
@device function routine2(theta)
3434
2 => Rx(theta)
3535
end
3636

test/printing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using YaoLocations
44
using YaoArrayRegister
55
using YaoCompiler.Intrinsics
66

7-
@operation function test_intrinsic(theta, phi)
7+
@device function test_intrinsic(theta, phi)
88
# syntax sugar
99
1 => X
1010
@gate 2 => Z

test/zx.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using YaoHIR
1010
using ZXCalculus
1111
using YaoArrayRegister
1212

13-
@operation function test_a()
13+
@device function test_a()
1414
1 => X
1515
1 => X
1616
end
@@ -26,7 +26,7 @@ ir, = code_typed(Intrinsics.apply, (AnyReg, typeof(test_a())); interp)[1]
2626
Expr(:invoke, _, apply, _, &(QuoteNode(H)), &(QuoteNode(Locations(1))))::Nothing
2727
end
2828

29-
@operation function test_b()
29+
@device function test_b()
3030
1 => Rx(2.0)
3131
1 => Rz(3.0)
3232
end
@@ -40,7 +40,7 @@ ir, = code_typed(Intrinsics.apply, (AnyReg, typeof(test_b())); interp)[1]
4040
Expr(:invoke, _, apply, _, &(QuoteNode(Rz(3.0))), &(QuoteNode(Locations(1))))::Nothing
4141
end
4242

43-
@operation function test_cir()
43+
@device function test_cir()
4444
5 => H
4545
@ctrl 4 5 => X
4646
5 => shift(7 / 4 * π)

0 commit comments

Comments
 (0)