Example #1
0
 def test_build_macro_with_premade_parameters(self):
     param_ident = randomize.random_identifier()
     param = Parameter(param_ident, None)
     macro_ident = randomize.random_identifier()
     sexpr = ("macro", macro_ident, param, ("sequential_block",))
     exp_value = core.Macro(macro_ident, [param])
     act_value = build(sexpr)
     self.assertEqual(exp_value, act_value)
Example #2
0
 def test_build_map_single(self):
     rname = randomize.random_identifier()
     rsize = randomize.random_whole()
     mname = randomize.random_identifier()
     mindex = randomize.random_integer(lower=0, upper=rsize - 1)
     reg = Register(rname, rsize)
     exp_value = NamedQubit(mname, reg, mindex)
     sexpr = ("circuit", ("register", rname, rsize), ("map", mname, rname, mindex))
     circuit = build(sexpr)
     act_value = circuit.registers[mname]
     self.assertEqual(exp_value, act_value)
Example #3
0
 def test_build_map_full(self):
     # This requires a defined register to test so this requires a circuit.
     rname = randomize.random_identifier()
     rsize = randomize.random_whole()
     mname = randomize.random_identifier()
     sexpr = ("circuit", ("register", rname, rsize), ("map", mname, rname))
     reg = Register(rname, rsize)
     exp_value = Register(mname, alias_from=reg)
     circuit = build(sexpr)
     act_value = circuit.registers[mname]
     self.assertEqual(exp_value, act_value)
Example #4
0
 def test_build_let(self):
     name = randomize.random_identifier()
     value = randomize.random_integer()
     sexpr = ("let", name, value)
     exp_value = Constant(name, value)
     act_value = build(sexpr)
     self.assertEqual(exp_value, act_value)
Example #5
0
 def test_build_register(self):
     name = randomize.random_identifier()
     size = randomize.random_whole()
     sexpr = ("register", name, size)
     exp_value = Register(name, size)
     act_value = build(sexpr)
     self.assertEqual(exp_value, act_value)
Example #6
0
 def test_build_anonymous_gate(self):
     # To test this we're going to create a gate, then take the temporary definition that is created in the process,
     # and use that to create an identical gate.
     name = randomize.random_identifier()
     args = (1, 3.14)
     sexpr = ("gate", name, *args)
     act_value = build(sexpr)
     gate_def = act_value.gate_def
     exp_value = gate_def(*args)
     self.assertEqual(exp_value, act_value)
Example #7
0
 def test_build_map_slice(self):
     rname = randomize.random_identifier()
     rsize = randomize.random_whole()
     mname = randomize.random_identifier()
     mstart = randomize.random_integer(lower=0, upper=rsize - 1)
     mstop = randomize.random_integer(lower=1, upper=rsize)
     mstep = randomize.random_integer(lower=1, upper=rsize)
     # The Register type doesn't seem to work with None (default) slice parameters, so we don't test that here.
     # it's not clear if that's something to worry about.
     mslice = slice(mstart, mstop, mstep)
     reg = Register(rname, rsize)
     exp_value = Register(mname, alias_from=reg, alias_slice=mslice)
     sexpr = (
         "circuit",
         ("register", rname, rsize),
         ("map", mname, rname, mstart, mstop, mstep),
     )
     circuit = build(sexpr)
     act_value = circuit.registers[mname]
     self.assertEqual(exp_value, act_value)
Example #8
0
 def test_build_native_gate(self):
     name = randomize.random_identifier()
     parameters = [Parameter("a", ParamType.INT), Parameter("b", ParamType.FLOAT)]
     gate_def = GateDefinition(name, parameters=parameters)
     native_gates = {name: gate_def}
     a = 5
     b = 1.234
     sexpr = ("gate", name, a, b)
     exp_value = gate_def(a, b)
     act_value = build(sexpr, native_gates)
     self.assertEqual(exp_value, act_value)