nodes: 0, module; 1, function_definition; 2, function_name:append_variables; 3, parameters; 4, block; 5, identifier:self; 6, identifier:samples_like; 7, default_parameter; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, comment:# we don't handle multiple values; 12, if_statement; 13, comment:# append requires the new variables to be unique; 14, expression_statement; 15, if_statement; 16, expression_statement; 17, expression_statement; 18, return_statement; 19, identifier:sort_labels; 20, True; 21, comment:"""Create a new sampleset with the given variables with values added.
  
          Not defined for empty sample sets. Note that when `sample_like` is
          a :obj:`.SampleSet`, the data vectors and info are ignored.
  
          Args:
              samples_like:
                  Samples to add to the sample set. Should either be a single
                  sample or should match the length of the sample set. See
                  :func:`.as_samples` for what is allowed to be `samples_like`.
  
              sort_labels (bool, optional, default=True):
                  If true, returned :attr:`.SampleSet.variables` will be in
                  sorted-order. Note that mixed types are not sortable in which
                  case the given order will be maintained.
  
          Returns:
              :obj:`.SampleSet`: A new sample set with the variables/values added.
  
          Examples:
  
              >>> sampleset = dimod.SampleSet.from_samples([{'a': -1, 'b': +1},
              ...                                           {'a': +1, 'b': +1}],
              ...                                          dimod.SPIN,
              ...                                          energy=[-1.0, 1.0])
              >>> new = sampleset.append_variables({'c': -1})
              >>> print(new)
                 a  b  c energy num_oc.
              0 -1 +1 -1   -1.0       1
              1 +1 +1 -1    1.0       1
              ['SPIN', 2 rows, 2 samples, 3 variables]
  
              Add variables from another sampleset to the original above. Note
              that the energies do not change.
  
              >>> another = dimod.SampleSet.from_samples([{'c': -1, 'd': +1},
              ...                                         {'c': +1, 'd': +1}],
              ...                                        dimod.SPIN,
              ...                                        energy=[-2.0, 1.0])
              >>> new = sampleset.append_variables(another)
              >>> print(new)
                 a  b  c  d energy num_oc.
              0 -1 +1 -1 +1   -1.0       1
              1 +1 +1 +1 +1    1.0       1
              ['SPIN', 2 rows, 2 samples, 4 variables]
  
          """; 22, assignment; 23, assignment; 24, comparison_operator:samples.shape[0] == num_samples; 25, comment:# we don't need to do anything, it's already the correct shape; 26, block; 27, elif_clause; 28, else_clause; 29, assignment; 30, call; 31, block; 32, assignment; 33, assignment; 34, call; 35, pattern_list; 36, call; 37, identifier:num_samples; 38, call; 39, subscript; 40, identifier:num_samples; 41, pass_statement; 42, boolean_operator; 43, block; 44, block; 45, identifier:variables; 46, attribute; 47, identifier:any; 48, generator_expression; 49, expression_statement; 50, raise_statement; 51, identifier:new_variables; 52, binary_operator:list(variables) + labels; 53, identifier:new_samples; 54, call; 55, attribute; 56, argument_list; 57, identifier:samples; 58, identifier:labels; 59, identifier:as_samples; 60, argument_list; 61, identifier:len; 62, argument_list; 63, attribute; 64, integer:0; 65, comparison_operator:samples.shape[0] == 1; 66, identifier:num_samples; 67, expression_statement; 68, expression_statement; 69, raise_statement; 70, identifier:self; 71, identifier:variables; 72, comparison_operator:v in variables; 73, for_in_clause; 74, assignment; 75, call; 76, call; 77, identifier:labels; 78, attribute; 79, argument_list; 80, call; 81, identifier:from_samples; 82, tuple; 83, attribute; 84, keyword_argument; 85, comment:# make a copy; 86, keyword_argument; 87, dictionary_splat; 88, identifier:samples_like; 89, identifier:self; 90, identifier:samples; 91, identifier:shape; 92, subscript; 93, integer:1; 94, assignment; 95, assignment; 96, call; 97, identifier:v; 98, identifier:variables; 99, identifier:v; 100, identifier:labels; 101, identifier:msg; 102, string:"Appended samples cannot contain variables in sample set"; 103, identifier:ValueError; 104, argument_list; 105, identifier:list; 106, argument_list; 107, identifier:np; 108, identifier:hstack; 109, tuple; 110, identifier:type; 111, argument_list; 112, identifier:new_samples; 113, identifier:new_variables; 114, identifier:self; 115, identifier:vartype; 116, identifier:info; 117, call; 118, identifier:sort_labels; 119, identifier:sort_labels; 120, attribute; 121, attribute; 122, integer:0; 123, identifier:samples; 124, call; 125, identifier:msg; 126, parenthesized_expression; 127, identifier:ValueError; 128, argument_list; 129, identifier:msg; 130, identifier:variables; 131, attribute; 132, identifier:samples; 133, identifier:self; 134, attribute; 135, argument_list; 136, identifier:self; 137, identifier:data_vectors; 138, identifier:samples; 139, identifier:shape; 140, attribute; 141, argument_list; 142, concatenated_string; 143, identifier:msg; 144, attribute; 145, identifier:sample; 146, identifier:copy; 147, identifier:deepcopy; 148, attribute; 149, identifier:np; 150, identifier:repeat; 151, identifier:samples; 152, identifier:num_samples; 153, keyword_argument; 154, string:"mismatched shape. The samples to append should either be "; 155, string:"a single sample or should match the length of the sample "; 156, string:"set. Empty sample sets cannot be appended to."; 157, identifier:self; 158, identifier:record; 159, identifier:self; 160, identifier:info; 161, identifier:axis; 162, integer:0
code: def append_variables(self, samples_like, sort_labels=True):
          """Create a new sampleset with the given variables with values added.
  
          Not defined for empty sample sets. Note that when `sample_like` is
          a :obj:`.SampleSet`, the data vectors and info are ignored.
  
          Args:
              samples_like:
                  Samples to add to the sample set. Should either be a single
                  sample or should match the length of the sample set. See
                  :func:`.as_samples` for what is allowed to be `samples_like`.
  
              sort_labels (bool, optional, default=True):
                  If true, returned :attr:`.SampleSet.variables` will be in
                  sorted-order. Note that mixed types are not sortable in which
                  case the given order will be maintained.
  
          Returns:
              :obj:`.SampleSet`: A new sample set with the variables/values added.
  
          Examples:
  
              >>> sampleset = dimod.SampleSet.from_samples([{'a': -1, 'b': +1},
              ...                                           {'a': +1, 'b': +1}],
              ...                                          dimod.SPIN,
              ...                                          energy=[-1.0, 1.0])
              >>> new = sampleset.append_variables({'c': -1})
              >>> print(new)
                 a  b  c energy num_oc.
              0 -1 +1 -1   -1.0       1
              1 +1 +1 -1    1.0       1
              ['SPIN', 2 rows, 2 samples, 3 variables]
  
              Add variables from another sampleset to the original above. Note
              that the energies do not change.
  
              >>> another = dimod.SampleSet.from_samples([{'c': -1, 'd': +1},
              ...                                         {'c': +1, 'd': +1}],
              ...                                        dimod.SPIN,
              ...                                        energy=[-2.0, 1.0])
              >>> new = sampleset.append_variables(another)
              >>> print(new)
                 a  b  c  d energy num_oc.
              0 -1 +1 -1 +1   -1.0       1
              1 +1 +1 +1 +1    1.0       1
              ['SPIN', 2 rows, 2 samples, 4 variables]
  
          """
          samples, labels = as_samples(samples_like)
  
          num_samples = len(self)
  
          # we don't handle multiple values
          if samples.shape[0] == num_samples:
              # we don't need to do anything, it's already the correct shape
              pass
          elif samples.shape[0] == 1 and num_samples:
              samples = np.repeat(samples, num_samples, axis=0)
          else:
              msg = ("mismatched shape. The samples to append should either be "
                     "a single sample or should match the length of the sample "
                     "set. Empty sample sets cannot be appended to.")
              raise ValueError(msg)
  
          # append requires the new variables to be unique
          variables = self.variables
          if any(v in variables for v in labels):
              msg = "Appended samples cannot contain variables in sample set"
              raise ValueError(msg)
  
          new_variables = list(variables) + labels
          new_samples = np.hstack((self.record.sample, samples))
  
          return type(self).from_samples((new_samples, new_variables),
                                         self.vartype,
                                         info=copy.deepcopy(self.info),  # make a copy
                                         sort_labels=sort_labels,
                                         **self.data_vectors)