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

[BUG] Drawing a ControlledQubitUnitary returns TypeError #1171

Closed
DSGuala opened this issue Mar 26, 2021 · 1 comment · Fixed by #1174
Closed

[BUG] Drawing a ControlledQubitUnitary returns TypeError #1171

DSGuala opened this issue Mar 26, 2021 · 1 comment · Fixed by #1174
Assignees
Labels
bug 🐛 Something isn't working

Comments

@DSGuala
Copy link
Contributor

DSGuala commented Mar 26, 2021

Issue description

Trying to use the circuit drawer with qml.ControlledQubitUnitary raises the error TypeError: unsupported format string passed to numpy.ndarray.__format_

import pennylane as qml
from pennylane import numpy as np

dev = qml.device("default.qubit", wires=3)

U = np.array([[ 0.94877869,  0.31594146], [-0.31594146,  0.94877869]])

@qml.qnode(dev)
def circuit():
    qml.ControlledQubitUnitary(U, control_wires=[0, 1], wires=2)
    return qml.probs(range(3))

circuit()
circuit.draw()
  • Expected behavior:
    circuit.draw() returns a string representing the circuit

  • Actual behavior:
    circuit.draw() raises the error TypeError: unsupported format string passed to numpy.ndarray.__format_

  • Reproduces how often:
    Always

  • System information:

Name: PennyLane
Version: 0.15.0.dev0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author: None
Author-email: None
License: Apache License 2.0
Requires: appdirs, autograd, networkx, numpy, scipy, semantic-version, toml
Required-by: 
Platform info:           Linux-5.8.0-48-generic-x86_64-with-glibc2.29
Python version:          3.8.5
Numpy version:           1.19.5
Scipy version:           1.4.1
Installed devices:
- default.gaussian (PennyLane-0.15.0.dev0)
- default.mixed (PennyLane-0.15.0.dev0)
- default.qubit (PennyLane-0.15.0.dev0)
- default.qubit.autograd (PennyLane-0.15.0.dev0)
- default.qubit.jax (PennyLane-0.15.0.dev0)
- default.qubit.tf (PennyLane-0.15.0.dev0)
- default.tensor (PennyLane-0.15.0.dev0)
- default.tensor.tf (PennyLane-0.15.0.dev0)

Tracebacks

<ipython-input-6-2b516653526b> in <module>
     12 
     13 circuit()
---> 14 circuit.draw()

~pennylane/pennylane/qnode.py in draw(self, charset, wire_order, show_all_wires)
    685             )
    686 
--> 687         return self.qtape.draw(
    688             charset=charset, wire_order=wire_order, show_all_wires=show_all_wires
    689         )

~pennylane/pennylane/tape/tape.py in draw(self, charset, wire_order, show_all_wires)
   1003             str: the circuit representation of the tape
   1004         """
-> 1005         return self.graph.draw(
   1006             charset=charset,
   1007             wire_order=wire_order,

~pennylane/pennylane/circuit_graph.py in draw(self, charset, wire_order, show_all_wires)
    572             )
    573 
--> 574         drawer = CircuitDrawer(
    575             grid,
    576             obs,

~pennylane/pennylane/circuit_drawer/circuit_drawer.py in __init__(self, raw_operation_grid, raw_observable_grid, wires, charset, show_all_wires)
     79 
     80         # Resolve operator names
---> 81         self.resolve_representation(self.operation_grid, self.operation_representation_grid)
     82         self.resolve_representation(self.observable_grid, self.observable_representation_grid)
     83 

~pennylane/pennylane/circuit_drawer/circuit_drawer.py in resolve_representation(self, grid, representation_grid)
    160                 representation_layer[
    161                     wire_indices
--> 162                 ] = self.representation_resolver.element_representation(operator, wire)
    163 
    164             representation_grid.append_layer(representation_layer)

~pennylane/pennylane/circuit_drawer/representation_resolver.py in element_representation(self, element, wire)
    455             return self.output_representation(element, wire)
    456 
--> 457         return self.operator_representation(element, wire)

~pennylane/pennylane/circuit_drawer/representation_resolver.py in operator_representation(self, op, wire)
    394         else:
    395             representation = "{}({})".format(
--> 396                 name, ", ".join([self.single_parameter_representation(par) for par in op.data])
    397             )
    398 

~pennylane/pennylane/circuit_drawer/representation_resolver.py in <listcomp>(.0)
    394         else:
    395             representation = "{}({})".format(
--> 396                 name, ", ".join([self.single_parameter_representation(par) for par in op.data])
    397             )
    398 

~pennylane/pennylane/circuit_drawer/representation_resolver.py in single_parameter_representation(par)
    116             return par
    117 
--> 118         return f"{1.0 * par:.3g}"
    119 
    120     @staticmethod
@github-actions github-actions bot added the bug 🐛 Something isn't working label Mar 26, 2021
@DSGuala DSGuala changed the title [BUG] Drawing a ControlledQubitUnitary [BUG] Drawing a ControlledQubitUnitary returns TypeError Mar 26, 2021
@antalszava
Copy link
Contributor

Thanks @DSGuala for catching this! Will post a fix shortly. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants