From de650a6dc54e154adbf7caaa82e42edf6521df4f Mon Sep 17 00:00:00 2001 From: LMquentinLR Date: Sat, 19 Mar 2022 23:47:11 +0100 Subject: [PATCH 1/2] recursive:bool added to _resolve_parameters_ args, change towards TwoQubitGate deprecation --- chapter09/cirq/qnn.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/chapter09/cirq/qnn.py b/chapter09/cirq/qnn.py index 2337452..ec2e522 100644 --- a/chapter09/cirq/qnn.py +++ b/chapter09/cirq/qnn.py @@ -7,8 +7,7 @@ import sympy # Class for a ZX gate in Cirq -class ZXGate(cirq.ops.eigen_gate.EigenGate, - cirq.ops.gate_features.TwoQubitGate): +class ZXGate(cirq.ops.eigen_gate.EigenGate): """ZXGate with variable weight.""" def __init__(self, weight=1): @@ -19,6 +18,10 @@ def __init__(self, weight=1): """ self.weight = weight super().__init__(exponent=weight) # Automatically handles weights other than 1 + def _num_qubits_(self): + """Indicates the number of qubits + replaces inheriting the superclass TwoQubitGate""" + return 2 def _eigen_components(self): return [ @@ -33,7 +36,7 @@ def _eigen_components(self): ] # This lets the weight be a Symbol. Useful for parameterization. - def _resolve_parameters_(self, param_resolver): + def _resolve_parameters_(self, param_resolver, recursive=True): return ZXGate(weight=param_resolver.value_of(self.weight)) # How should the gate look in ASCII diagrams? @@ -76,7 +79,7 @@ def readout_expectation(state): # Specify an explicit qubit order so that we know which qubit is the readout result = simulator.simulate(qnn, resolver, qubit_order=[readout]+data_qubits, initial_state=state_num) - wf = result.final_state + wf = result.final_state_vector # Becase we specified qubit order, the Z value of the readout is the most # significant bit. From 72f3fcb8fa187ebf1eb25444dbc676322941e98b Mon Sep 17 00:00:00 2001 From: LMquentinLR Date: Sat, 19 Mar 2022 23:51:10 +0100 Subject: [PATCH 2/2] recursive:bool added to _resolve_parameters_ args, change towards TwoQubitGate deprecation --- chapter09/cirq/qnn.py | 1 + 1 file changed, 1 insertion(+) diff --git a/chapter09/cirq/qnn.py b/chapter09/cirq/qnn.py index ec2e522..c5b74aa 100644 --- a/chapter09/cirq/qnn.py +++ b/chapter09/cirq/qnn.py @@ -18,6 +18,7 @@ def __init__(self, weight=1): """ self.weight = weight super().__init__(exponent=weight) # Automatically handles weights other than 1 + def _num_qubits_(self): """Indicates the number of qubits replaces inheriting the superclass TwoQubitGate"""