Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module 'qutip.qip.circuit' has no attribute 'gate_expand_1toN' and 'gate_expand_2toN' #20

Open
MrSago opened this issue Aug 31, 2021 · 3 comments

Comments

@MrSago
Copy link

MrSago commented Aug 31, 2021

File "...\learn-qc-with-python-and-qsharp\ch05\simulator.py", line 88, in _apply
    matrix = qt.circuit.gate_expand_1toN(
AttributeError: module 'qutip.qip.circuit' has no attribute 'gate_expand_1toN'


File "...\learn-qc-with-python-and-qsharp\ch06\simulator.py", line 124, in _apply
  matrix = qt.circuit.gate_expand_2toN(unitary,
AttributeError: module 'qutip.qip.circuit' has no attribute 'gate_expand_2toN'
@MrSago MrSago changed the title Module 'qutip.qip.circuit' has no attribute 'gate_expand_1toN' Module 'qutip.qip.circuit' has no attribute 'gate_expand_1toN' and 'gate_expand_2toN' Aug 31, 2021
@nadimragab
Copy link

Please use qt.gate_expand_1toN instead of qt.circuit.gate_expand_1toN because gate_expand_1toN, refer to https://qutip.org/docs/latest/modules/qutip/qip/operations/gates.html for more details

@sufyanAbbasi
Copy link

I'd also recommend locking your qutip install to 4.7.6, i.e. pip install qutip==4.7.6, as qutip version 5 doesn't have that method anymore. Unfortunately, I'm not sure what the version 5 equivalent is.

@Florian-Heringa
Copy link

In version 5.1.0 you can use the qutip.expand_operator() function. This is a generalised version of the gate_expand_ntoN() functions so the input is a bit different. In this case I got it to work by doing this: matrix = qt.expand_operator(unitary, [2] * self.capacity, ids[0]) in the _apply() method of the Simulator. Similar for the measure() method of the SimulatedQubit: qt.expand_operator(qt.basis(2, outcome) * qt.basis(2, outcome).dag(), [2] *self.parent.capacity, self.qubit_id).

This works since the function expects the dimensionality of the composite systems, in this case simple qubits, which have 2 states. So multiplying this by the amount of qubits gives the total dimensionality specification. In the old version this was handled on a case-by-case basis so this was not necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants