Ejemplo n.º 1
0
 def test_single_qubit_gate_init(self):
     single_qubit_gate = AbstractGate('X', 1, 10.0, 1, False)
     self.assertEqual('X', single_qubit_gate.get_name())
     self.assertEqual(1, single_qubit_gate.get_span())
     self.assertEqual(10.0, single_qubit_gate.get_time())
     self.assertEqual(1, single_qubit_gate.get_n_parameters())
     self.assertEqual(False, single_qubit_gate.get_is_variational())
     self.assertEqual('default', single_qubit_gate.get_type())
     self.assertEqual([], single_qubit_gate.get_indexes())
     self.assertEqual([], single_qubit_gate.get_targets())
Ejemplo n.º 2
0
 def test_two_qubit_gate_init(self):
     two_qubit_gate = AbstractGate('XX', 2, 10.0, 1, True)
     self.assertEqual('XX', two_qubit_gate.get_name())
     self.assertEqual(2, two_qubit_gate.get_span())
     self.assertEqual(10.0, two_qubit_gate.get_time())
     self.assertEqual(1, two_qubit_gate.get_n_parameters())
     self.assertEqual(True, two_qubit_gate.get_is_variational())
     self.assertEqual('default', two_qubit_gate.get_type())
     self.assertEqual([], two_qubit_gate.get_indexes())
     self.assertEqual([], two_qubit_gate.get_targets())
Ejemplo n.º 3
0
    def test_circuit_three_qubits(self):
        single_qubit_gate = AbstractGate('X', 1, 10.0, 1, False)
        two_qubit_gate = AbstractGate('ZZ', 2, 40.0, 1, True)
        circuit = build_n_qubit_circuit_test(3, True)

        self.assertEqual(circuit.get_n_parameters(False), 2)
        self.assertEqual(circuit.get_n_parameters(True), 2)
        for index, gate in enumerate(circuit.basic_block[0]):
            self.assertEqual(gate.__str__(), 'X\t' + str(index) + '\tc0')
        for index, gate in enumerate(circuit.basic_block[2]):
            self.assertEqual(gate.__str__(), 'X\t' + str(index) + '\tc1')
        for index, gate in enumerate(circuit.basic_block[1]):
            self.assertEqual(gate.__str__(), 'ZZ\t0,1\tv0')
        for index, gate in enumerate(circuit.basic_block[3]):
            self.assertEqual(gate.__str__(), 'ZZ\t1,2\tv1')
Ejemplo n.º 4
0
    def test_circuit_four_qubits(self):
        single_qubit_gate = AbstractGate('X', 1, 10.0, 1, False)
        two_qubit_gate = AbstractGate('ZZ', 2, 40.0, 1, True)
        circuit = build_n_qubit_circuit_test(4, False)

        self.assertEqual(circuit.get_n_parameters(False), 8)
        self.assertEqual(circuit.get_n_parameters(True), 3)
        for index, gate in enumerate(circuit.basic_block[0]):
            self.assertEqual(gate.__str__(), 'X\t' + str(index) + '\tc' +
                             str(index))
        for index, gate in enumerate(circuit.basic_block[2]):
            self.assertEqual(gate.__str__(), 'X\t' + str(index) + '\tc' +
                             str(index+4))
        self.assertEqual(circuit.basic_block[1][0].__str__(), 'ZZ\t0,1\tv0')
        self.assertEqual(circuit.basic_block[1][1].__str__(), 'ZZ\t2,3\tv1')
        self.assertEqual(circuit.basic_block[3][0].__str__(), 'ZZ\t1,2\tv2')
Ejemplo n.º 5
0
def build_n_qubit_circuit_test(n, option):
    """ Build a circuit test for an n qubit register
    with a block comprising 2 layers of single qubit rotations
    interleaved with odd and even layers of adjayent two qubit gates

    Args:
        n (integer): number of qubits
        option (boolean): choose to have (or not) the same parameters
            per layer
    """
    single_qubit_gate = AbstractGate('X', 1, 10.0, 1, False)
    two_qubit_gate = AbstractGate('ZZ', 2, 40.0, 1, True)
    circuit_example = AbstractCircuit(n)
    # add first layer of single qubit rotations
    circuit_example.add_adyacent_gates_layer(single_qubit_gate, option)
    # add even layer of two qubit gates
    circuit_example.add_adyacent_gates_layer(two_qubit_gate, option, False)
    # add second layer of single qubit rotations
    circuit_example.add_adyacent_gates_layer(single_qubit_gate, option)
    # add odd layer of two qubit gates
    circuit_example.add_adyacent_gates_layer(two_qubit_gate, option, True)

    return circuit_example
Ejemplo n.º 6
0
 def test_bad_action_add_gate_in_layer_wrong_targets_len(self):
     gate = AbstractGate('ZZZ', 3, 40.0, 1, True)
     circuit_example = AbstractCircuit(2)
     with self.assertRaises(ValueError):
         circuit_example.add_gate_as_layer(gate, [0, 1])
Ejemplo n.º 7
0
 def test_bad_action_add_adyacent_gates_layer_nqubits_error(self):
     gate = AbstractGate('ZZZ', 3, 40.0, 1, True)
     circuit_example = AbstractCircuit(2)
     with self.assertRaises(ValueError):
         circuit_example.add_adyacent_gates_layer(gate, True, False)
Ejemplo n.º 8
0
 def test_print_method_three_qubits_constant(self):
     gate = AbstractGate('XXY', 3, 10.0, 1, False)
     gate.assign_qubit_indexes([0, 1, 2])
     gate.assign_parameter_indexes([1])
     self.assertEqual(gate.__str__(), 'XXY\t0,1,2\tc1')
Ejemplo n.º 9
0
 def test_print_method_three_qubits_variational(self):
     gate = AbstractGate('XXY', 3, 10.0, 1, True)
     gate.assign_qubit_indexes([0, 1, 2])
     gate.assign_parameter_indexes([1])
     self.assertEqual(gate.__str__(), 'XXY\t0,1,2\tv1')
Ejemplo n.º 10
0
 def test_assign_qubit_indexes(self):
     gate = AbstractGate('XXY', 3, 10.0, 1, True)
     gate.assign_qubit_indexes([0, 1, 2])
     self.assertEqual([0, 1, 2], gate.get_targets())
Ejemplo n.º 11
0
 def test_init_bad_action_span(self):
     with self.assertRaises(ValueError):
         _ = AbstractGate('XX', 'J', 10.0, 1, True)
Ejemplo n.º 12
0
 def test_assign_parameter_indexes(self):
     gate = AbstractGate('XXY', 3, 10.0, 1, True)
     gate.assign_parameter_indexes([0])
     self.assertEqual([0], gate.get_indexes())
Ejemplo n.º 13
0
 def test_bad_action_assign_qubit_indexes(self):
     gate = AbstractGate('XXY', 3, 10.0, 1, True)
     with self.assertRaises(AbstractGateError):
         _ = gate.assign_qubit_indexes([0])
Ejemplo n.º 14
0
 def test_init_bad_action_gate_type(self):
     with self.assertRaises(ValueError):
         _ = AbstractGate('XX', 1, -10.0, 1, False, 4)
Ejemplo n.º 15
0
 def test_init_bad_action_is_variational(self):
     with self.assertRaises(ValueError):
         _ = AbstractGate('XX', 1, -10.0, 1, 2)
Ejemplo n.º 16
0
 def test_init_bad_action_n_parameters(self):
     with self.assertRaises(ValueError):
         _ = AbstractGate('XX', 1, 10.0, 'J', True)
Ejemplo n.º 17
0
 def test_init_bad_action_time_negative(self):
     with self.assertRaises(ValueError):
         _ = AbstractGate('XX', 1, -10.0, 1, True)
Ejemplo n.º 18
0
 def test_print_method_one_qubit_constant(self):
     gate = AbstractGate('X', 1, 10.0, 1, False)
     gate.assign_qubit_indexes([0])
     gate.assign_parameter_indexes([1])
     self.assertEqual(gate.__str__(), 'X\t0\tc1')
Ejemplo n.º 19
0
 def test_print_method_one_qubit_variational(self):
     gate = AbstractGate('X', 1, 10.0, 1, True)
     gate.assign_qubit_indexes([0])
     gate.assign_parameter_indexes([1])
     self.assertEqual(gate.__str__(), 'X\t0\tv1')
Ejemplo n.º 20
0
 def test_init_bad_action_name(self):
     with self.assertRaises(ValueError):
         _ = AbstractGate(1, 2, 10.0, 1, True)