1
$\begingroup$

I've been using qiskit for about a year now, and as of late, I've had issues finding an available backend to run my circuit on. Looking into the matter, I reinstalled qiskit to find that most everything had changed quite a bit. Now when I try to run just a basic test circuit program, taken from the tutorial I get this:

~$ python3 test.py

Traceback (most recent call last):
  File "test.py", line 27, in <module>
    job = execute(circ, backend)
  File "/home/micciche/.local/lib/python3.5/site-packages/qiskit/tools/compiler.py", line 108, in execute
    skip_transpiler, seed_mapper, pass_manager, memory)
  File "/home/micciche/.local/lib/python3.5/site-packages/qiskit/tools/compiler.py", line 67, in compile
    coupling_map=coupling_map, seed=seed, memory=memory)
  File "/home/micciche/.local/lib/python3.5/site-packages/qiskit/converters/circuits_to_qobj.py", line 61, in circuits_to_qobj
    coupling_map))
  File "/home/micciche/.local/lib/python3.5/site-packages/qiskit/converters/circuits_to_qobj.py", line 92, in _circuit_to_experiment
    json_circuit = DagUnroller(dag, JsonBackend(dag.basis)).execute()
  File "/home/micciche/.local/lib/python3.5/site-packages/qiskit/unroll/_dagunroller.py", line 38, in execute
    self._process()
  File "/home/micciche/.local/lib/python3.5/site-packages/qiskit/unroll/_dagunroller.py", line 161, in _process
    self.backend.new_qreg(name, width)
  File "/home/micciche/.local/lib/python3.5/site-packages/qiskit/unroll/_jsonbackend.py", line 98, in new_qreg
    assert size >= 0, "invalid qreg size"
  TypeError: unorderable types: QuantumRegister() >= int()

Does anybody know how to resolve this? Thanks.

Edit: This is the code I tried to run, which I just copied from a tutorial:

import numpy as np
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import execute

# Create a Quantum Register with 3 qubits.
q = QuantumRegister(3, 'q')

# Create a Quantum Circuit acting on the q register
circ = QuantumCircuit(q)

# Add a H gate on qubit 0, putting this qubit in superposition.
circ.h(q[0])
# Add a CX (CNOT) gate on control qubit 0 and target qubit 1, putting
# the qubits in a Bell state.
circ.cx(q[0], q[1])
# Add a CX (CNOT) gate on control qubit 0 and target qubit 2, putting
# the qubits in a GHZ state.
circ.cx(q[0], q[2])

# Import Aer
from qiskit import BasicAer

# Run the quantum circuit on a statevector simulator backend
backend = BasicAer.get_backend('statevector_simulator')

# Create a Quantum Program for execution
job = execute(circ, backend)

result = job.result()

outputstate = result.get_statevector(circ, decimals=3)
print(outputstate)
$\endgroup$
  • $\begingroup$ Can you include the running code? $\endgroup$ – cnada Jan 10 at 10:23
  • 1
    $\begingroup$ To second James' answer, I would recommend if you are still having problems to install Qiskit in a virtual environment via the Conda route on the installation guide. I've seen many issues with colleagues from dependency clashes. $\endgroup$ – Ben Jaderberg Jan 10 at 15:32
1
$\begingroup$

The code you provide works fine for me, so I guess that something is wrong with your installation.

I recommend running the command

pip uninstall qiskit

and also

pip uninstall qiskit-terra
pip uninstall qiskit-aqua
pip uninstall qiskit-aer

and then reinstalling with

pip install qiskit
$\endgroup$
  • $\begingroup$ Thank you very much! $\endgroup$ – Anthony Micciche Jan 10 at 16:24

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.