lambeq
lambeq copied to clipboard
TypeError when construct quantum circuits for multi-classification task
Hi, I’m trying to set up a model for multi-classification task with 4 classes (0 to 3) and wondering if I can ask some questions regarding allocation of qubits when building an ansatz. The dataset consists of label and its corresponding sentence as shown below:
0 joyful man entertains kid 2 young kid irritates man 3 frightened woman startles woman 1 old woman grieves kid 0 old man entertains woman
I encoded the classical labels into two-qubit representation such as label_mapping = {'0': (0, 0), '1': (0, 1), '2': (1, 0), '3': (1, 1)}.
- Cups reader: When Cups reader was used to process the data then turned into the string diagrams, I defined two qubits for each diagram, ansatz = IQPAnsatz({AtomicType.NOUN: 0, AtomicType.SENTENCE: 2}, n_layers=1), so that individual post-selected quantum state can be compared with label_mapping. But this approach gave me the Type error:
`309 for i, circuit in enumerate(circuits): 310 n_bits = len(circuit.post_processing.dom) --> 311 result = np.zeros(*(n_bits * (2, ))) 312 for bitstring, count in counts[i].items(): 313 result[bitstring] = count
TypeError: Cannot interpret '2' as a data type
`
- Spiders reader: Using the spiders reader with the same ansatz specification also gave me the type error, but this time, the error was raised by not correctly defining domain and codomain, which I’ve never seen in the previous lambeq version:
`1927 dom_check = self.ob_with_cache(ar.dom) 1928 if ret.cod != cod_check or ret.dom != dom_check: -> 1929 raise TypeError(f'The arrow is ill-defined. Applying the functor ' 1930 f'to a box returns dom = {ret.dom}, cod = ' 1931 f'{ret.cod} expected dom = {dom_check}, cod = ' 1932 f'{cod_check}') 1933 return ret
TypeError: The arrow is ill-defined. Applying the functor to a box returns dom = , cod = qubit expected dom = , cod =`
It looks like changing the number of qubits in ansatz doesn’t help resolve the issue, so I wonder if anyone can help me with this.
Thanks! (+ I’m using the latest version of lambeq 0.4.0)