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

V0.17.0 deprecations #1522

Merged
merged 11 commits into from
Aug 13, 2021
Merged

V0.17.0 deprecations #1522

merged 11 commits into from
Aug 13, 2021

Conversation

antalszava
Copy link
Contributor

@antalszava antalszava commented Aug 12, 2021

  • Deprecate the tape methods get_resources and get_depth as they are superseded by specs;
  • Fully deprecate qml.sample when shots=None: raise an error in QubitDevice instead of a warning

@antalszava antalszava changed the base branch from master to v0.17.0-rc0 August 12, 2021 16:14
@antalszava antalszava marked this pull request as ready for review August 12, 2021 16:24
@antalszava
Copy link
Contributor Author

[ch8061]

Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my end @antalszava, however it seems that some tests are now failing!

Also, this may break some demos(?)

.github/CHANGELOG.md Outdated Show resolved Hide resolved
.github/CHANGELOG.md Outdated Show resolved Hide resolved
antalszava and others added 3 commits August 12, 2021 16:12
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
@antalszava antalszava changed the base branch from v0.17.0-rc0 to master August 12, 2021 20:20
@codecov
Copy link

codecov bot commented Aug 12, 2021

Codecov Report

Merging #1522 (4e5c1b9) into master (5c0adbc) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1522      +/-   ##
==========================================
- Coverage   98.21%   98.21%   -0.01%     
==========================================
  Files         184      184              
  Lines       13218    13209       -9     
==========================================
- Hits        12982    12973       -9     
  Misses        236      236              
Impacted Files Coverage Δ
pennylane/tape/tape.py 98.56% <ø> (-0.04%) ⬇️
pennylane/_qubit_device.py 98.64% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c0adbc...4e5c1b9. Read the comment docs.

@antalszava
Copy link
Contributor Author

Thank you Josh!

  1. Indeed, two tests were using qml.sample without specifying the number of shots, adjusted these.
  2. Good question!

Changed to have master as the base, so that we can make sure we're good by running CI.

Manually the following demos seem to be the ones with qml.sample, all of which also specify the number of shots:

  • tutorial_vqls.py
    dev_x = qml.device("default.qubit", wires=n_qubits, shots=n_shots)

    @qml.qnode(dev_x)
    def prepare_and_sample(weights):

        # Variational circuit generating a guess for the solution vector |x>
        variational_block(weights)

        # We assume that the system is measured in the computational basis.
        # If we label each basis state with a decimal integer j = 0, 1, ... 2 ** n_qubits - 1,
        # this is equivalent to a measurement of the following diagonal observable.
        basis_obs = qml.Hermitian(np.diag(range(2 ** n_qubits)), wires=range(n_qubits))

        return qml.sample(basis_obs)
  • tutorial_jax_transformations.py
        dev = qml.device("default.qubit.jax", wires=2, shots=10, prng_key=key)

        # Now we can create our qnode within the circuit function.
        @qml.qnode(dev, interface="jax")
        def my_circuit():
            qml.RX(param, wires=0)
            qml.CNOT(wires=[0, 1])
            return qml.sample(qml.PauliZ(0))
  • tutorial_qaoa_maxcut.py
    dev = qml.device("default.qubit", wires=n_wires, shots=1)

    @qml.qnode(dev)
    def circuit(gammas, betas, edge=None, n_layers=1):
        # apply Hadamards to get the n qubit |+> state
        for wire in range(n_wires):
            qml.Hadamard(wires=wire)
        # p instances of unitary operators
        for i in range(n_layers):
            U_C(gammas[i])
            U_B(betas[i])
        if edge is None:
            # measurement phase
            return qml.sample(comp_basis_measurement(range(n_wires)))
  • qsim_beyond_classical.py
dev = qml.device('cirq.qsim', wires=wires, qubits=qubits, shots=shots)

@qml.qnode(dev)
def circuit(seed=42, return_probs=False):
    np.random.seed(seed)
    gate_idx = generate_single_qubit_gate_list()

    # m full cycles - single-qubit gates & two-qubit gate
    for i, gs in enumerate(gate_sequence):
        for w in range(wires):
            single_qubit_gates[gate_idx[i][w]](wires=w)

        for qb_1, qb_2 in gate_order[gs]:
            ops.ISWAP(wires=(qb_1, qb_2))
            ops.CPhase(-np.pi/6, wires=(qb_1, qb_2))

    # one half-cycle - single-qubit gates only
    for w in range(wires):
        single_qubit_gates[gate_idx[-1][w]](wires=w)

    if return_probs:
        return qml.probs(wires=range(wires))
    else:
        return [qml.sample(qml.PauliZ(i)) for i in range(wires)]

dev_x = qml.device("default.qubit", wires=n_qubits, shots=n_shots)
  • tutorial_coherent_vqls.py
dev_x = qml.device("default.qubit", wires=n_qubits, shots=n_shots)

@qml.qnode(dev_x)
def prepare_and_sample(weights):

    # Variational circuit generating a guess for the solution vector |x>
    variational_block(weights)

    # We assume that the system is measured in the computational basis.
    # If we label each basis state with a decimal integer j = 0, 1, ... 2 ** n_qubits - 1,
    # this is equivalent to a measurement of the following diagonal observable.
    basis_obs = qml.Hermitian(np.diag(range(2 ** n_qubits)), wires=range(n_qubits))

    return qml.sample(basis_obs)

Copy link
Contributor

@thisac thisac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as far as I can tell. 💯 Nice to get the deprecated functions out of the way.

I guess we'd like this to be merged into the rc branch though, right?

@@ -12,6 +12,7 @@ help:
@echo " wheel to build the PennyLane wheel"
@echo " dist to package the source distribution"
@echo " clean to delete all temporary, cache, and build files"
@echo " docs to build the PennyLane documentation"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

@antalszava
Copy link
Contributor Author

antalszava commented Aug 12, 2021

Thank you for the review @thisac! My plan would be to merge first into master and check that the demos are passing well in the qml repo just for extra safety. Then will create an identical PR to add this into the rc branch.

Edit: created the rc version: #1524. Once the CI checks are okay with this version in master, will merge that too.

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

Successfully merging this pull request may close these issues.

3 participants