def test_pass_through_core_type(self):
     test_values = [
         Parameter("foo", None),
         Register("r", 3),
     ]
     for value in test_values:
         self.assertEqual(value, build(value))
Beispiel #2
0
def make_map_full(reg, name=None, return_params=False):
    """Make a map alias to the given register."""
    if name is None:
        name = random_identifier()
    map_reg = Register(name, alias_from=reg)
    if not return_params:
        return map_reg
    else:
        return map_reg, name
Beispiel #3
0
def make_random_register(name=None, size=None, return_params=False):
    """Make a random register"""
    if name is None:
        name = random_identifier()
    if size is None:
        size = random_whole()
    reg = Register(name, size)
    if not return_params:
        return reg
    else:
        return reg, name, size
Beispiel #4
0
def make_map_slice(reg, name=None, map_slice=None, return_params=False):
    """Make a map alias to a slice of the given register."""
    if name is None:
        name = random_identifier()
    if map_slice is None:
        map_slice = make_random_slice(reg.size)
    map_reg = Register(name, alias_from=reg, alias_slice=map_slice)
    if not return_params:
        return map_reg
    else:
        return map_reg, name, map_slice
 def test_build_map_with_let(self):
     sexpr = (
         "circuit",
         ("let", "a", 1),
         ("register", "r", 10),
         ("map", "q", "r", "a"),
     )
     reg = Register("r", 10)
     const = Constant("a", 1)
     exp_value = NamedQubit("q", reg, const)
     circuit = build(sexpr)
     act_value = circuit.registers["q"]
     self.assertEqual(exp_value, act_value)
Beispiel #6
0
 def test_create_register_invalid_parameter(self):
     """Test creating a register in various invalid ways."""
     reg = common.make_random_register()
     with self.assertRaises(Exception):
         # No size or origin
         Register(random_identifier())
     with self.assertRaises(Exception):
         # size and slice
         Register(
             random_identifier(),
             size=random_whole(),
             alias_slice=common.make_random_slice(reg.size),
         )
     with self.assertRaises(Exception):
         # size and slice plus an alias register
         Register(
             random_identifier(),
             size=random_whole(),
             alias_from=reg,
             alias_slice=common.make_random_slice(reg.size),
         )
     with self.assertRaises(Exception):
         # alias register and size
         Register(random_identifier(), size=random_whole(), alias_from=reg)