Skip to content

Commit 87625bd

Browse files
authored
Merge pull request #318 from tequilahub/devel
Update to v.1.9.1
2 parents c7c00d8 + 2ed821f commit 87625bd

File tree

6 files changed

+31
-17
lines changed

6 files changed

+31
-17
lines changed

Diff for: src/tequila/circuit/gates.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,14 @@ def map_qubits(self, qubit_map: dict):
10811081
def compile(self, exponential_pauli=False, *args, **kwargs):
10821082
# optimized compiling for single and double qubit excitaitons following arxiv:2005.14475
10831083
# Alternative representation in arxiv:2104.05695 (not implemented -> could be added and controlled with optional compile keywords)
1084+
if self.is_controlled():
1085+
control = list(self.control)
1086+
else:
1087+
control = []
10841088
if self.compile_options == "optimize" and len(self.target) == 2 and exponential_pauli:
10851089
p,q = self.target
10861090
U0 = X(target=p, control=q)
1087-
U1 = Ry(angle=self.parameter, target=q, control=p)
1091+
U1 = Ry(angle=self.parameter, target=q, control=[p]+control)
10881092
return U0 + U1 + U0
10891093
elif self.compile_options == "optimize" and len(self.target) == 4 and exponential_pauli:
10901094
p,r,q,s = self.target
@@ -1093,10 +1097,11 @@ def compile(self, exponential_pauli=False, *args, **kwargs):
10931097
U0 += X(target=r, control=p)
10941098
U0 += X(target=q)
10951099
U0 += X(target=s)
1096-
U1 = Ry(angle=-self.parameter, target=p, control=[q,r,s])
1100+
U1 = Ry(angle=-self.parameter, target=p, control=[q,r,s]+control)
10971101
return U0 + U1 + U0.dagger()
10981102
else:
1099-
return Trotterized(angle=self.parameter, generator=self.generator, steps=1)
1103+
return Trotterized(angle=self.parameter, generator=self.generator, steps=1, control=self.control)
1104+
11001105

11011106
def _convert_Paulistring(paulistring: typing.Union[PauliString, str, dict]) -> PauliString:
11021107
'''

Diff for: src/tequila/optimizers/optimizer_gd.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,12 @@ def __call__(self, objective: Objective,
334334

335335

336336
if not self.silent:
337+
self.__dx = numpy.asarray(self.__dx)
337338
print("%3i %+15.8f %+7.2e %7.3e %7.3e %s"
338339
% (step,
339340
e,
340341
e-last,
341-
numpy.max(abs(self.__dx)),
342+
numpy.max([abs(x) for x in self.__dx]),
342343
numpy.sqrt(numpy.average(self.__dx**2)),
343344
comment))
344345

Diff for: src/tequila/quantumchemistry/pyscf_interface.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ def __init__(self, parameters: ParametersQC,
4646
# solve restricted HF
4747
mf = pyscf.scf.RHF(mol)
4848
mf.kernel()
49-
self.irreps = mf.get_irrep_nelec()
49+
50+
# only works if point_group is not C1
51+
# otherwise PySCF uses a different SCF object
52+
# irrep information is however not critical to tequila
53+
if hasattr(mf, "get_irrep_nelec"):
54+
self.irreps = mf.get_irrep_nelec()
55+
else:
56+
self.irreps = None
57+
5058
orbital_energies = mf.mo_energy
5159

5260
# compute mo integrals

Diff for: src/tequila/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "1.9.0"
1+
__version__ = "1.9.1"
22
__author__ = "Tequila Developers "

Diff for: tests/test_noise_opt.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def test_dependencies():
1717

1818

1919
@pytest.mark.skipif(len(samplers) == 0, reason="Missing necessary backends")
20-
@pytest.mark.parametrize("simulator", [numpy.random.choice(samplers)])
2120
@pytest.mark.parametrize("p", numpy.random.uniform(0.1, .4, 1))
2221
@pytest.mark.parametrize('method', numpy.random.choice(['NELDER-MEAD', 'COBYLA'],1))
23-
def test_bit_flip_scipy_gradient_free(simulator, p, method):
22+
def test_bit_flip_scipy_gradient_free(p, method):
23+
simulator = numpy.random.choice(samplers)
2424
qubit = 0
2525
H = paulis.Qm(qubit)
2626
U = gates.Rx(target=qubit, angle=tq.Variable('a'))
@@ -31,11 +31,11 @@ def test_bit_flip_scipy_gradient_free(simulator, p, method):
3131

3232

3333
@pytest.mark.skipif(len(samplers) == 0, reason="Missing necessary backends")
34-
@pytest.mark.parametrize("simulator", [numpy.random.choice(samplers)])
3534
@pytest.mark.parametrize("p", numpy.random.uniform(0.1, .4, 1))
3635
@pytest.mark.parametrize('method',
3736
[tq.optimizer_scipy.OptimizerSciPy.gradient_based_methods[numpy.random.randint(0, 4, 1)[0]]])
38-
def test_bit_flip_scipy_gradient(simulator, p, method):
37+
def test_bit_flip_scipy_gradient(p, method):
38+
simulator = numpy.random.choice(samplers)
3939
qubit = 0
4040
H = paulis.Qm(qubit)
4141
U = gates.Rx(target=qubit, angle=tq.Variable('a'))
@@ -46,11 +46,11 @@ def test_bit_flip_scipy_gradient(simulator, p, method):
4646

4747

4848
@pytest.mark.skipif(len(samplers) == 0, reason="Missing necessary backends")
49-
@pytest.mark.parametrize("simulator", [numpy.random.choice(samplers)])
5049
@pytest.mark.parametrize("p", numpy.random.uniform(0.1, .4, 1))
5150
@pytest.mark.parametrize('method',
5251
[["TRUST-KRYLOV", "NEWTON-CG", "TRUST-NCG", "TRUST-CONSTR"][numpy.random.randint(0, 4, 1)[0]]])
53-
def test_bit_flip_scipy_hessian(simulator, p, method):
52+
def test_bit_flip_scipy_hessian(p, method):
53+
simulator = numpy.random.choice(samplers)
5454
qubit = 0
5555
H = paulis.Qm(qubit)
5656
U = gates.Rx(target=qubit, angle=tq.Variable('a'))
@@ -62,9 +62,9 @@ def test_bit_flip_scipy_hessian(simulator, p, method):
6262

6363
@pytest.mark.skipif(len(samplers) == 0, reason="Missing necessary backends")
6464
@pytest.mark.skipif(not tq.optimizers.has_phoenics, reason="Missing phoenics installation")
65-
@pytest.mark.parametrize("simulator", [numpy.random.choice(samplers)])
6665
@pytest.mark.parametrize("p", numpy.random.uniform(0.1, .4, 1))
67-
def test_bit_flip_phoenics(simulator, p):
66+
def test_bit_flip_phoenics(p):
67+
simulator = numpy.random.choice(samplers)
6868
qubit = 0
6969
H = paulis.Qm(qubit)
7070
U = gates.Rx(target=qubit, angle=tq.Variable('a'))
@@ -75,10 +75,10 @@ def test_bit_flip_phoenics(simulator, p):
7575

7676
@pytest.mark.skipif(len(samplers) == 0, reason="Missing necessary backends")
7777
@pytest.mark.skipif(not tq.optimizers.has_gpyopt, reason="Missing gpyopt installation")
78-
@pytest.mark.parametrize("simulator", [numpy.random.choice(samplers)])
7978
@pytest.mark.parametrize("p", numpy.random.uniform(0.1, .4, 1))
8079
@pytest.mark.parametrize('method', ['lbfgs', 'DIRECT', 'CMA'])
81-
def test_bit_flip_gpyopt(simulator, p, method):
80+
def test_bit_flip_gpyopt(p, method):
81+
simulator = numpy.random.choice(samplers)
8282
qubit = 0
8383
H = paulis.Qm(qubit)
8484
U = gates.Rx(target=qubit, angle=tq.Variable('a'))

Diff for: tests/test_simulator_backends.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
HAS_GOOGLE = importlib.util.find_spec('cirq_google')
21-
@pytest.mark.skipif(condition=HAS_GOOGLE, reason="cirq_google not installed")
21+
@pytest.mark.skipif(condition=not HAS_GOOGLE, reason="cirq_google not installed")
2222
def test_cirq_google_devices():
2323
import cirq_google
2424

0 commit comments

Comments
 (0)