JackHidary / quantumcomputingbook

Companion site for the textbook Quantum Computing: An Applied Approach
784 stars 217 forks source link

qnn.py issues with recent Cirq versions #40

Open qlero opened 2 years ago

qlero commented 2 years ago

Hello,

It seems that the qnn.py script in chapter 9 is broken for Cirq versions v0.11.0 and further, as per the release notes here, notably:

If you have old gate implementations with _resolve_parameter that doesn't support the recursive parameter, you will get an error message: TypeError: _resolve_parameters_() takes 2 positional arguments but 3 were given, you will need to add support for the recursive:bool parameter

Solution

The script can be solved by:

I can submit a pull request unless you have specified somewhere you're using a Cirq version older than the v0.11.0.

Best regards,

Quentin

JackHidary commented 2 years ago

yes - pls submit the pull request thx

On Mar 19, 2022, at 6:01 PM, quentin le roux @.***> wrote:

 Hello,

It seems that the qnn.py script in chapter 9 is broken for Cirq versions v0.11.0 and further, as per the release notes here, notably:

If you have old gate implementations with _resolve_parameter that doesn't support the recursive parameter, you will get an error message: TypeError: _resolveparameters() takes 2 positional arguments but 3 were given, you will need to add support for the recursive:bool parameter

Solution

The script can be solved by:

line 36 -- adding recursive=True to def _resolveparameters(self, param_resolver, recursive=True): line 79 -- and replacing wf = result.final_state with wf = result.final_state_vector I can submit a pull request unless you have specified somewhere you're using a Cirq version older than the v0.11.0.

Best regards,

Quentin

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you are subscribed to this thread.

qlero commented 2 years ago

Hello,

I submitted a pull request with the modifications. Of note, I also provided another modification:

With cirq v0.14, the class TwoQubitGate (and the three-qubit one) will be deprecated. This is solved by removing the cirq.ops.gate_features.TwoQubitGate as an inheritance argument from the class ZXGate (and others in different scripts) on lines 10-11, and replacing it with the following function in the class body:

def _num_qubits_(self):
        return 2

Best regards,

Quentin