Bug in Codercise I.12.1

Hey, I noticed a bug in codercise I.12.1 where the following code produces an error

num_wires = 2
dev = qml.device('default.qubit', wires=num_wires)

@qml.qnode(dev)
def apply_cnot(basis_id):
    """Apply a CNOT to |basis_id>.

    Args:
        basis_id (int): An integer value identifying the basis state to construct.
      
    Returns:
        array[complex]: The resulting state after applying CNOT|basis_id>.
    """

    # Prepare the basis state |basis_id>
    bits = [int(x) for x in np.binary_repr(basis_id, width=dev.num_wires)]
    qml.BasisStatePreparation(bits, wires=[0, 1])

    ##################
    # YOUR CODE HERE #
    ##################

    # APPLY THE CNOT
    qml.CNOT(wires=[0,1])
    
    return qml.state()


##################
# YOUR CODE HERE #
##################

# REPLACE THE BIT STRINGS VALUES BELOW WITH THE CORRECT ONES
cnot_truth_table = {
    "00" : "00",
    "01" : "01",
    "10" : "11",
    "11" : "10"
}


# Run your QNode with various inputs to help fill in your truth table
print(apply_cnot(0))

Error: ‘DefaultQubit’ object has no attribute ‘num_wires’

This seems to be fixed by changing the width argument in line 17 so that the line reads,

bits = [int(x) for x in np.binary_repr(basis_id, width=len(dev.wires))]

Hi @keegan.sherman, welcome to the Forum!

Thank you for reporting this bug. It does look like upon a version update we missed this change. Thank you for letting us know!

We hope you’re enjoying the Codebook and please let us know of any other issues you may find.