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

Poetry updates #184

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
1,709 changes: 836 additions & 873 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ license = "MIT"

[tool.poetry.dependencies]
python = "^3.8"
openfermion = "^1.3.0"
openfermion = "^1.6.1"
cached-property = "^1.5.2"
qiskit = "^0.44.0"
qiskit = "^1.0.2"
pydocstyle = "^6.1.1"
isort = "^5.10.1"
black = "^22.1.0"
Expand All @@ -18,7 +18,7 @@ ncon = "^1.0.0"
opt-einsum = "^3.3.0"
pytest = "^7.2.2"
numba = "0.58.1"
quimb = "^1.5.1"
quimb = "^1.7.3"
ray = "^2.6.3"
sphinx-design = "^0.5.0"
myst-nb = "^0.17.2"
Expand Down
11 changes: 8 additions & 3 deletions symmer/evolution/circuit_symmerlator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from symmer import PauliwordOp, QuantumState
from qiskit import QuantumCircuit
import numpy as np
from qiskit import qasm3
import re

class CircuitSymmerlator:
"""
Expand Down Expand Up @@ -171,12 +173,15 @@ def from_qasm(cls, qasm: str, angle_factor: int=1) -> "CircuitSymmerlator":
qasm_version = instructions.pop(0)
inclusions = instructions.pop(0)
registers = instructions.pop(0)
n_qubits = int(registers.split(' ')[1][2:-1])
# n_qubits = int(registers.split(' ')[1][2:-1])
n_qubits = int(re.findall(r'\d+', registers)[0])

self = cls(n_qubits)
pi = np.pi # for evaluating strings like '3*pi/2'
for step in instructions:
gate, qubits = step.split(' ')
gate_qubits = step.split(' ')
gate = gate_qubits[0]
qubits = ''.join(gate_qubits[1:])
qubits = [int(q[2:-1]) for q in qubits.split(',')]
extract_angle = gate.split('(')
if len(extract_angle) == 1:
Expand All @@ -195,4 +200,4 @@ def from_qasm(cls, qasm: str, angle_factor: int=1) -> "CircuitSymmerlator":
def from_qiskit(cls, circuit: QuantumCircuit) -> "CircuitSymmerlator":
""" Initialize the simulator from a Qiskit QuantumCircuit
"""
return cls.from_qasm(circuit.reverse_bits().qasm(), angle_factor=-1)
return cls.from_qasm(qasm3.dumps(circuit.reverse_bits()), angle_factor=-1)
6 changes: 3 additions & 3 deletions symmer/evolution/variational_optimization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from cached_property import cached_property
from qiskit.opflow import CircuitStateFn
from qiskit.quantum_info import Statevector
from qiskit import QuantumCircuit
from symmer import process, QuantumState, PauliwordOp
from symmer.operators.utils import (
Expand Down Expand Up @@ -83,7 +83,7 @@ def get_state(self,
if self.expectation_eval == 'observable_rotation':
return list(zip(evolution_obj, -2*x))
else:
state = CircuitStateFn(evolution_obj.bind_parameters(x))
state = Statevector(evolution_obj.bind_parameters(x))
if self.expectation_eval == 'dense_array':
return state.to_matrix().reshape([-1,1])
elif self.expectation_eval == 'sparse_array':
Expand Down Expand Up @@ -344,7 +344,7 @@ def f(index, obs):
gradient = list(map(self._derivative_from_commutators, range(self.excitation_pool.n_terms)))

elif self.derivative_eval == 'param_shift':
# not parallelizable due the CircuitStateFn already using multiprocessing!
# not parallelizable due the Statevector already using multiprocessing!
gradient = list(map(self._derivative_from_param_shift, range(self.excitation_pool.n_terms)))

else:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_evolution/test_circuit_symmerlator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_random_cliffords():
assert np.isclose(
(sv.conj().T @ observable_matrix @ sv)[0,0],
CS.evaluate(observable)
)
), f'{(sv.conj().T @ observable_matrix @ sv)[0,0]} vs {CS.evaluate(observable)}'

#### INDIVIDUAL GATE TESTS BELOW ####

Expand Down Expand Up @@ -139,4 +139,4 @@ def test_CZ_gate(P):
CS = CircuitSymmerlator(2)
CS.CZ(0,1)
P = PauliwordOp.from_list([P])
assert CS.apply_sequence(P) == CZ(2,0,1)*P*CZ(2,0,1)
assert CS.apply_sequence(P) == CZ(2,0,1)*P*CZ(2,0,1)
Loading