From 569d5273468a6f71390062e055f7101731d65e61 Mon Sep 17 00:00:00 2001 From: Radomir Stevanovic Date: Mon, 6 Jul 2020 12:06:37 -0700 Subject: [PATCH] Avoid casting to fileview-able BQM on upload, if possible --- dwave/cloud/solver.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/dwave/cloud/solver.py b/dwave/cloud/solver.py index c92f09ab..803acc2f 100644 --- a/dwave/cloud/solver.py +++ b/dwave/cloud/solver.py @@ -360,19 +360,21 @@ def _bqm_as_fileview(bqm): # XXX: temporary until something like dwavesystems/dimod#599 is implemented. try: + import dimod from dimod.serialization.fileview import FileView as BQMFileView - from dimod import AdjVectorBQM except ImportError: # pragma: no cover return if isinstance(bqm, BQMFileView): return bqm - try: - if not isinstance(bqm, AdjVectorBQM): + # test explicitly to avoid copy on cast if possible + fileviewable = (dimod.AdjArrayBQM, dimod.AdjVectorBQM, dimod.AdjMapBQM) + if not isinstance(bqm, fileviewable): + try: bqm = AdjVectorBQM(bqm) - except: - return + except: + return try: return BQMFileView(bqm)